Reputation: 4485
Can va_list
s handle C++ references? I know they can handle ints, doubles and pointers, but not floats, chars, etc. Can they handle C++ references?
Upvotes: 0
Views: 137
Reputation: 106246
You should #include <cstdarg>
rather than <stdarg.h>
...
If the caller provides a reference as an argument to such a function, the call will work the same way as if the referenced object was specified directly. For example, if you have:
void f(...);
T my_t;
T& x = my_t;
f(my_t);
f(x);
The values passed in registers and/or on the stack as arguments for f
will be the same in both calls (assuming out-of line calls, and functionally equivalent if inlined).
So, "can they handle C++ references" - yes, in the way described above, which may or may not be what you wanted/expected.
Just a word of caution: if you have...
f(A& b, ...);
...the behaviour is undefined, as the va_start
macro doesn't support having the final pre-...
-matching argument be a reference (you can't pass a lambda capture nor pack expansion either). See C++ Standard [cstdarg.syn] paragraph 1 for full details.
Upvotes: 3