fork download
  1. #include <stdio.h>
  2.  
  3. #define I_HATE_MACRO2(a, b) a ## b
  4. #define I_HATE_MACRO(a, b) I_HATE_MACRO2(a, b)
  5. #define ARRAY_LENGTH(len, a) \
  6.   typedef struct { \
  7.   int I_HATE_MACRO(must_be_an_array_,__LINE__) : ((void*)&(a) == (void*)(a)); \
  8.   } I_HATE_MACRO(must_be_an_array_,__LINE__); \
  9.   const size_t len = sizeof(a) / sizeof(a[0]);
  10.  
  11. int main() {
  12. int test[] = {1,2,3};
  13. int test2;
  14. int *test3;
  15.  
  16. ARRAY_LENGTH(testlen, test);
  17. ARRAY_LENGTH(testlen2, test2);
  18. ARRAY_LENGTH(testlen3, test3);
  19.  
  20. printf("%d\n", testlen);
  21.  
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:17: error: bit-field ‘must_be_an_array_17’ width not an integer constant
prog.c:17: error: subscripted value is neither array nor pointer
prog.c:18: error: bit-field ‘must_be_an_array_18’ width not an integer constant
prog.c:18: warning: unused variable ‘testlen3’
prog.c:17: warning: unused variable ‘testlen2’
stdout
Standard output is empty