C++11 variable number of arguments, same specific type

A possible solution is to make the parameter type a container that can be initialized by a brace initializer list, such as std::initializer_list<int> or std::vector<int>. For example: #include <iostream> #include <initializer_list> void func(std::initializer_list<int> a_args) { for (auto i: a_args) std::cout << i << ‘\n’; } int main() { func({4, 7}); func({4, 7, 12, 14}); }

Is there a way to use C++ preprocessor stringification on variadic macro arguments?

You can use various recursive macro techniques to do things with variadic macros. For example, you can define a NUM_ARGS macro that counts the number of arguments to a variadic macro: #define _NUM_ARGS(X100, X99, X98, X97, X96, X95, X94, X93, X92, X91, X90, X89, X88, X87, X86, X85, X84, X83, X82, X81, X80, X79, X78, … Read more

How do vararg functions find out the number of arguments in machine code?

The trick is that you tell them somehow else. For printf you have to supply a format string which even contains type information (which might be incorrect though). The way to supply this information is mainly user-contract and often error-prone. As for calling conventions: Usually the arguments are pushed onto the stack from left to … Read more

Passing parameters dynamically to variadic functions

Variadic functions use a calling convention where the caller is responsible for popping the function parameters from the stack, so yes, it is possible to do this dynamically. It’s not standardized in C, and normally would require some assembly to manually push the desired parameters, and invoke the variadic function correctly. The cdecl calling convention … Read more

Objective-C passing around … nil terminated argument lists

You can’t do this, at least not in the way you’re wanting to do it. What you want to do (pass on the variable arguments) requires having an initializer on UIAlertView that accepts a va_list. There isn’t one. However, you can use the addButtonWithTitle: method: + (void)showWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, … Read more