fork download
  1. #include <stdio.h>
  2.  
  3. #define ARG_ARRAY(...) ((int[]) { __VA_ARGS__ })
  4. #define ARG_COUNT(...) (sizeof (ARG_ARRAY(__VA_ARGS__)) / sizeof (int))
  5.  
  6. #define STUFF(label, ...) \
  7.   stuff(label, ARG_COUNT(__VA_ARGS__), ARG_ARRAY(__VA_ARGS__))
  8.  
  9. void stuff(char *label, int count, int *values) {
  10. printf("[%s] count %d", label, count);
  11.  
  12. for (int i = 0; i < count; i++) {
  13. printf("%s %d", (i == 0) ? ":" : ",", values[i]);
  14. }
  15.  
  16. printf("\n");
  17. }
  18.  
  19. int return1(void) {
  20. printf("Called `return1()`.\n");
  21. return 1;
  22. }
  23.  
  24. int main(int argc, char **argv) {
  25. STUFF("blort");
  26. STUFF("frotz", return1());
  27. STUFF("fizmo", 2 + 3, 6 + 1);
  28. STUFF("glorf", 99, 999, 999);
  29. STUFF("igram", 9, 8, 7, 6, 5, 4, 3, 2, 1);
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:25:18: error: ISO C99 requires rest arguments to be used [-Werror]
     STUFF("blort");
                  ^
prog.c:3:33: error: ISO C forbids empty initializer braces [-Werror=pedantic]
 #define ARG_ARRAY(...) ((int[]) { __VA_ARGS__ })
                                 ^
prog.c:4:33: note: in expansion of macro ‘ARG_ARRAY’
 #define ARG_COUNT(...) (sizeof (ARG_ARRAY(__VA_ARGS__)) / sizeof (int))
                                 ^
prog.c:7:18: note: in expansion of macro ‘ARG_COUNT’
     stuff(label, ARG_COUNT(__VA_ARGS__), ARG_ARRAY(__VA_ARGS__))
                  ^
prog.c:25:5: note: in expansion of macro ‘STUFF’
     STUFF("blort");
     ^
prog.c:25: confused by earlier errors, bailing out
stdout
Standard output is empty