For the following code:
void fun(char *msg, int n, int m, ...) {
va_list ptr;
va_start(ptr, m); // Question regarding this line
printf("%d ", va_arg(ptr, int));
}
The function is called as follows:
fun("Hello", 3, 54, 1, 7);
My question is regarding the line commented above. I tried the following three versions of that line:
va_start(ptr, msg);
va_start(ptr, n);
va_start(ptr, m);
In all the three cases I am getting "1" as the output. From what I have read, the second argument of va_start should be the last argument in the parameter list of the function fun(), i.e., va_start(ptr, m); should be the correct call. So why am I getting the same output in all the three cases.
[I ran the program on Ideone, if that is of any consequence.]