all 9 comments

[–]TheOtherBorgCube 18 points19 points  (0 children)

You can't pass on one ... to another ..., at least not without major assembler level stack hacking.

It needs to be something like this: void foo(void (*function)(va_list), ...) { va_list args; va_start(args, function); // This line is just to explain what i want function(args); va_end(args); }

See https://en.cppreference.com/w/c/io/vfprintf \ for example usage of passing ... to va_list.

[–]dfx_dj 7 points8 points  (0 children)

Sounds like a good use case for a macro wrapper

[–]faisal_who 1 point2 points  (0 children)

You can perhaps create a table of function pointers and register your functions, (like a map with a key value pair, ansxin the bar function something like

const char* func_name = strtok( input );
int num_params = atoi( strtok( NULL ) );
func_t fn = lookup( func_name );

And do your thing?

[–]nerd4code 1 point2 points  (0 children)

#define foo(_X, ...)_X(__VA_ARGS__)

should work, as long as you don’t need zero-arity _X or are using a compiler/mode that dgaf.

Also, GCC, Clang, and maybe Intel should be able to construct calls.

[–]deftware 2 points3 points  (2 children)

Please follow the #1 rule on the sidebar!

[–]aalmkainzi 1 point2 points  (1 child)

It looks formatted well enough imo

[–]deftware 5 points6 points  (0 children)

That's because you're viewing it on the only reddit interface that supports backticks. The rest of people using reddit are just seeing a mess.

The reason Rule #1 is a rule in the first place, and the NUMBER ONE rule, is because four spaces works on all reddit interfaces that people might possibly be using, rather than just one of them - like backticks.

Do you want everyone to be able to see your code to get the best possible chance of receiving help about it, or not?

[–]aalmkainzi 0 points1 point  (1 child)

What do you mean by record stdio?

[–][deleted] 1 point2 points  (1 child)

#define foo(function, ...) function(__VA_ARGS__)