fork download
  1. #include <stdio.h>
  2.  
  3. #ifdef GLOBAL_INSTANCE_DEBUG
  4. #define CREATE_GLOBAL(TYPE, VALUE) MAKE_GLOBAL_INSTANCE_DEBUG(TYPE, VALUE)
  5. #else
  6. #define CREATE_GLOBAL(TYPE, VALUE) MAKE_GLOBAL_INSTANCE(TYPE, VALUE)
  7. #endif
  8.  
  9. #define MAKE_GLOBAL_INSTANCE_DEBUG(TYPE, VALUE)\
  10.   static TYPE *VALUE(int line){\
  11.   static TYPE VALUE##_data;\
  12.   fprintf(stderr ,"use global instanse '%s' in %d.\n", #VALUE, line);\
  13.   return &VALUE##_data;\
  14.   }
  15. // end define
  16. #define MAKE_GLOBAL_INSTANCE(TYPE, VALUE)\
  17.   static TYPE *VALUE(int line){\
  18.   static TYPE VALUE##_data;\
  19.   return &VALUE##_data;\
  20.   }
  21. // end define
  22.  
  23. #define GLOBAL_ACCESS(VALUE) (*VALUE(__LINE__))
  24.  
  25. CREATE_GLOBAL(int, foo)
  26. #define foo GLOBAL_ACCESS(foo)
  27.  
  28. int main(void) {
  29. int foo = 2;
  30. printf("%d", foo);
  31. return 0;
  32. }
Compilation error #stdin compilation error #stdout 0.01s 1720KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:29: error: expected declaration specifiers or ‘...’ before numeric constant
prog.c:29: error: function ‘foo’ is initialized like a variable
prog.c:29: error: nested function ‘foo’ declared but never defined
stdout
Standard output is empty