Possible Duplicate:
Behaviour of printf when printing a %d without supplying variable name
What happens if I use, for example, printf("%d %d"); ? Will it just pop the last eight bytes from the stack and print them out?
In GCC - you get a warning (this is done using __attribute__ ((__warn_unused_result__))
).
On x86 you don't get a stack error, as the caller will push the data to the stack, and also pop after the function returned. This is called the C calling convention, unlike pascal - in which the function will also pop the data from the stack (using ret 10
in ASM for example).
The values of the data you required will be random.
Technically its undefined behaviour if the number of format specifiers in printf()
is greater than the number of arguments.
However the following is fine
printf("%d",x,y); // y is evaluated but not printed.
In that case, you'll get garbage data
which relies upon the compiler and its compiling option....
It will print garbage values but it has 'More % conversions than data arguments' warning.