fork download
  1. #include <stdio.h>
  2.  
  3. #define LIST int: foo1
  4. #define LIST LIST, double: foo2 // Add double to the list
  5. #define LIST LIST, default: bar // Add default
  6.  
  7. #define foo(X) _Generic((X), LIST)(X)
  8.  
  9.  
  10. void foo1(int x)
  11. {
  12. printf("foo1\n");
  13. }
  14.  
  15. void foo2(int x)
  16. {
  17. printf("foo2\n");
  18. }
  19.  
  20. void bar(char x)
  21. {
  22. printf("bar\n");
  23. }
  24.  
  25. int main(void)
  26. {
  27. foo(1);
  28. foo(1.1);
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4: warning: "LIST" redefined
 #define LIST LIST, double: foo2     // Add double to the list
 
prog.c:3: note: this is the location of the previous definition
 #define LIST int: foo1
 
prog.c:5: warning: "LIST" redefined
 #define LIST LIST, default: bar     // Add default
 
prog.c:4: note: this is the location of the previous definition
 #define LIST LIST, double: foo2     // Add double to the list
 
prog.c: In function ‘main’:
prog.c:5:14: error: unknown type name ‘LIST’
 #define LIST LIST, default: bar     // Add default
              ^~~~
prog.c:7:30: note: in expansion of macro ‘LIST’
 #define foo(X) _Generic((X), LIST)(X)
                              ^~~~
prog.c:27:5: note: in expansion of macro ‘foo’
     foo(1);
     ^~~
prog.c:5:14: error: unknown type name ‘LIST’
 #define LIST LIST, default: bar     // Add default
              ^~~~
prog.c:7:30: note: in expansion of macro ‘LIST’
 #define foo(X) _Generic((X), LIST)(X)
                              ^~~~
prog.c:28:5: note: in expansion of macro ‘foo’
     foo(1.1);
     ^~~
stdout
Standard output is empty