Playing with variadics a little, I discovered something interesting about how they are implemented in gcc.
Although the following produces warnings about the formats not matching up, it prints the three ints first and then the three doubles. This is because the values are passed in registers and when you ask for an int you get the one in the first int register; when you ask for a double, you get the one in the first double register.
Code:
#include <stdio.h>
int main() {
printf("%d %d %d %.1f %.1f %.1f\n",
1.1, 1, 2.2, 2, 3.3, 3);
return 0;
}
/* Output:
1 2 3 1.1 2.2 3.3
*/
Even our own variadic functions work that way. If you ask for an int, you will get the first int that was passed in. You need to overload (in the sense of overburden) the registers to screw it up.
Code:
#include <stdio.h>
int main() {
printf("%d %d %d %.1f %.1f %.1f\n"
"%d %d %d %.1f %.1f %.1f\n"
"%d %d %d %.1f %.1f %.1f\n"
"%d %d %d %.1f %.1f %.1f\n"
"%d %d %d %.1f %.1f %.1f\n",
1.1, 11, 2.1, 21, 3.1, 31,
1.2, 12, 2.2, 22, 3.2, 32,
1.3, 13, 2.3, 23, 3.3, 33,
1.4, 14, 2.4, 24, 3.4, 34,
1.5, 15, 2.5, 25, 3.5, 35);
return 0;
}
/* Output:
11 21 31 1.1 2.1 3.1
12 22 32 1.2 2.2 3.2
13 23 1717986918 1.3 2.3 0.0
1717986918 14 858993459 0.0 3.4 0.0
0 15 0 0.0 3.5 0.0
*/