fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define CREATE_0() printf("0\n")
  4. #define CREATE_1(x1) printf("1\n")
  5. #define CREATE_2(x1,x2) printf("2\n")
  6. #define CREATE_3(x1,x2,x3) printf("3\n")
  7. #define CREATE_4(x1,x2,x3,x4) printf("4\n")
  8. #define CREATE_5(x1,x2,x3,x4,x5) printf("5\n")
  9.  
  10. #define FUNC_CHOOSER(_f1, _f2, _f3, _f4, _f5, _f6, ...) _f6
  11. #define FUNC_RECOMPOSER(argsWithParentheses) FUNC_CHOOSER argsWithParentheses
  12. #define CHOOSE_FROM_ARG_COUNT(...) FUNC_RECOMPOSER((__VA_ARGS__, CREATE_5, CREATE_4, CREATE_3, CREATE_2, CREATE_1, ))
  13. #define NO_ARG_EXPANDER() ,,,,,CREATE_0
  14. #define MACRO_CHOOSER(...) CHOOSE_FROM_ARG_COUNT(NO_ARG_EXPANDER __VA_ARGS__ ())
  15. #define create(...) MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
  16.  
  17. int main() {
  18. create();
  19. create(1);
  20. create(1, 2);
  21. create(1, 2, 3);
  22. create(1, 2, 3, 4);
  23. create(1, 2, 3, 4, 5);
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 4564KB
stdin
Standard input is empty
stdout
0
1
2
3
4
5