fork download
  1. #define C_ASSERT(expr) extern char CAssertExtern[(expr)?1:-1]
  2.  
  3. #define NUM_ARGS__(X, \
  4.   N64,N63,N62,N61,N60, \
  5.   N59,N58,N57,N56,N55,N54,N53,N52,N51,N50, \
  6.   N49,N48,N47,N46,N45,N44,N43,N42,N41,N40, \
  7.   N39,N38,N37,N36,N35,N34,N33,N32,N31,N30, \
  8.   N29,N28,N27,N26,N25,N24,N23,N22,N21,N20, \
  9.   N19,N18,N17,N16,N15,N14,N13,N12,N11,N10, \
  10.   N09,N08,N07,N06,N05,N04,N03,N02,N01, N, ...) N
  11.  
  12. #define NUM_ARGS(...) \
  13.   NUM_ARGS__(0, __VA_ARGS__, \
  14.   64,63,62,61,60, \
  15.   59,58,57,56,55,54,53,52,51,50, \
  16.   49,48,47,46,45,44,43,42,41,40, \
  17.   39,38,37,36,35,34,33,32,31,30, \
  18.   29,28,27,26,25,24,23,22,21,20, \
  19.   19,18,17,16,15,14,13,12,11,10, \
  20.   9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
  21.  
  22. #define DECL_INIT_ARRAYN(TYPE, NAME, COUNT, N, ...) \
  23.   C_ASSERT(COUNT == N); \
  24.   TYPE NAME[COUNT] = { __VA_ARGS__ }
  25.  
  26. #define DECL_INIT_ARRAY(TYPE, NAME, COUNT, ...) \
  27.   DECL_INIT_ARRAYN(TYPE, NAME, COUNT, NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
  28.  
  29. DECL_INIT_ARRAY(const int, array3_3, 3, 1, 2, 3);
  30.  
  31. int main(void)
  32. {
  33. DECL_INIT_ARRAY(const int, array5_4, 5, 1, 2, 3, 4);
  34. DECL_INIT_ARRAY(const int, array5_6, 5, 1, 2, 3, 4, 5, 6);
  35. return 0;
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:33:3: error: size of array ‘CAssertExtern’ is negative
prog.c:34:3: error: size of array ‘CAssertExtern’ is negative
prog.c:34:3: error: excess elements in array initializer [-Werror]
prog.c:34:3: error: (near initialization for ‘array5_6’) [-Werror]
prog.c:34:3: error: unused variable ‘array5_6’ [-Werror=unused-variable]
prog.c:33:3: error: unused variable ‘array5_4’ [-Werror=unused-variable]
prog.c:34:3: error: unused variable ‘CAssertExtern’ [-Werror=unused-variable]
cc1: all warnings being treated as errors
stdout
Standard output is empty