I noticed that when using variadic functions, if I pass the va_arg() as parameter to a function, the parameters get passed in reverse. Is that expected?
For example, the following code outputs
Code:
#include <iostream>
#include <stdarg.h>
void foo_func(int v1, int v2)
{
std::cout << v1 << " " << v2 << std::endl;
}
void myfunc(int argc, ...)
{
va_list args;
va_start(args, argc);
int val1 = va_arg(args, int);
int val2 = va_arg(args, int);
foo_func(val1, val2);
va_end(args);
}
void myfunc2(int argc, ...)
{
va_list args;
va_start(args, argc);
foo_func(va_arg(args, int), va_arg(args, int));
va_end(args);
}
int main ()
{
myfunc(2, 1, 2);
myfunc2(2, 1, 2);
return 0;
}