fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define STATIC_ASSERT(COND) typedef char static_assertion_##__LINE__[(COND) ? 1 : -1]
  4. #define ENSURE_SIZE(structure, size) STATIC_ASSERT(sizeof(structure) == size)
  5.  
  6. typedef struct
  7. {
  8. unsigned a;
  9. unsigned b;
  10. } foo;
  11. ENSURE_SIZE(foo, sizeof(unsigned));
  12.  
  13. int main(void) {
  14. unsigned local_a = 0;
  15. foo *f = (foo *)(&local_a);
  16. printf("address local_a: %X, f->a: %X\n", &local_a, &f->a);
  17. return 0;
  18. }
  19.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:42: error: size of array 'static_assertion___LINE__' is negative
 #define STATIC_ASSERT(COND) typedef char static_assertion_##__LINE__[(COND) ? 1 : -1]
                                          ^
prog.c:4:38: note: in expansion of macro 'STATIC_ASSERT'
 #define ENSURE_SIZE(structure, size) STATIC_ASSERT(sizeof(structure) == size)
                                      ^
prog.c:11:1: note: in expansion of macro 'ENSURE_SIZE'
 ENSURE_SIZE(foo, sizeof(unsigned));
 ^
prog.c: In function 'main':
prog.c:16:9: warning: format '%X' expects argument of type 'unsigned int', but argument 2 has type 'unsigned int *' [-Wformat=]
  printf("address local_a: %X, f->a: %X\n", &local_a, &f->a);
         ^
prog.c:16:9: warning: format '%X' expects argument of type 'unsigned int', but argument 3 has type 'unsigned int *' [-Wformat=]
stdout
Standard output is empty