Add offsetof

This commit is contained in:
Rui Ueyama 2020-08-15 20:06:23 +09:00
parent 11fc259b01
commit 1b99badce4
2 changed files with 21 additions and 0 deletions

View File

@ -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
View 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;
}