mirror of
https://github.com/rui314/chibicc
synced 2024-11-24 07:09:42 +03:00
Add offsetof
This commit is contained in:
parent
11fc259b01
commit
1b99badce4
@ -8,4 +8,6 @@ typedef long ptrdiff_t;
|
||||
typedef unsigned int wchar_t;
|
||||
typedef long max_align_t;
|
||||
|
||||
#define offsetof(type, member) ((size_t)&(((type *)0)->member))
|
||||
|
||||
#endif
|
||||
|
19
test/offsetof.c
Normal file
19
test/offsetof.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include "test.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
int a;
|
||||
char b;
|
||||
int c;
|
||||
double d;
|
||||
} T;
|
||||
|
||||
int main() {
|
||||
ASSERT(0, offsetof(T, a));
|
||||
ASSERT(4, offsetof(T, b));
|
||||
ASSERT(8, offsetof(T, c));
|
||||
ASSERT(16, offsetof(T, d));
|
||||
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user