scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

0010-stddef.c (662B)


      1 #include <assert.h>
      2 #include <stddef.h>
      3 #include <stdio.h>
      4 
      5 /*
      6 output:
      7 NULL = 0
      8 end:
      9 */
     10 
     11 typedef struct test Test;
     12 
     13 struct test {
     14 	int a, b, c;
     15 	char d;
     16 } test = {
     17 	.a = 1,
     18 	.b = 2,
     19 	.c = 3,
     20 	.d = 4,
     21 };
     22 
     23 int
     24 main()
     25 {
     26 	wchar_t wc = L'c';
     27 	char *q, *p = (char *) &test;
     28 
     29 	printf("NULL = %p\n", NULL);
     30 
     31 	p += offsetof(Test, d);
     32 
     33 	assert(sizeof(size_t) == sizeof(ptrdiff_t));
     34 	assert(wc == L'c');
     35 	assert(*p == 4);
     36 	assert(offsetof(Test, d) > offsetof(Test, a));
     37 	assert(offsetof(Test, d) > offsetof(Test, b));
     38 	assert(offsetof(Test, d) > offsetof(Test, c));
     39 	assert(sizeof(sizeof(int)) == sizeof(size_t));
     40 	assert(sizeof(p - q) == sizeof(ptrdiff_t));
     41 
     42 	return 0;
     43 }