fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define VA_EXAMPLE(...) (varargsExample((NameAndLong[]){__VA_ARGS__}))
  4. typedef struct NameAndLong { const char* name; long long value; } NameAndLong;
  5. long varargsExample(NameAndLong things[]);
  6.  
  7. int main(int argc, char **argv)
  8. {
  9. VA_EXAMPLE(
  10. {"TestInt", 0},
  11. {"TestIntNegative", -1},
  12. {"TestLong", 0},
  13. {"TestSomethingBig",1LL<<62},
  14. {"TestLongNegative", -1},
  15. {NULL});
  16. return 0;
  17. }
  18.  
  19. long varargsExample(NameAndLong things[])
  20. {
  21. const char * name;
  22. long long nextValue;
  23. while ((name = things->name) != 0)
  24. {
  25. nextValue = things++->value;
  26. printf("Got [%s] with value [%lld]\n", name, nextValue);
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Got [TestInt] with value [0]
Got [TestIntNegative] with value [-1]
Got [TestLong] with value [0]
Got [TestSomethingBig] with value [4611686018427387904]
Got [TestLongNegative] with value [-1]