How can I call (not define) a function with a variable number of arguments in C?

前端 未结 6 1803
感情败类
感情败类 2021-01-20 01:05

Is there any way to make this code shorter?

long call_f(int argc, long *argv) {
  switch (argc) {
    case 0:
      return f();
      break;
    case 1:
             


        
6条回答
  •  既然无缘
    2021-01-20 01:18

    No, there isn't any good way to do this. See here: http://c-faq.com/varargs/handoff.html

    You can write a macro with token pasting to hide this behavior but that macro will be no simpler than this code, thus it's only worth writing if you have multiple functions like f() where you would otherwise have to duplicate this case statement.

提交回复
热议问题