Under 32bit environment, b is usually zero. This can be found
-Wall
option with gcc. However, if this printf is
indirectly called, like
void
my_printf(const char *fmt, ...);
This becomes much hard. The bug here is just typo, but breaking
your stack. Since a
may be 64 bit, and on 32 bit
environment, long int (%ld) is usually 32bit. Then va_arg macro
only takes 32bit from the stack. Then, b
is taken from
the next of stack, but it is still part of a
. If you
write the code as the following, it seems bug is gone. But the bug
is just hidden, deeply.
#include <cstdio>
int main()
{
long long int a = 0;
size_t b = 12;
printf("a = %ld\n", a);
printf("b = %ld\n", b);
}