I have a very simple C program where I am printing variables of different sizes.
#include <stdio.h>
unsigned int long long a;
unsigned int c;
int main() {
a = 0x1111111122222222;
c = 0x33333333;
printf("Sizes: %zu %zu\n", sizeof(a), sizeof(c));
printf("Seg: %llx %x\n", a, c);
printf("Seg: %lx %x\n", a, c);
printf("Seg: %x\n", c);
return 0;
}
On a 64-bit machine, all works fine.
On a 32-bit machine though, if I use an incorrect formatter for the first argument (second printf), I get incorrect output for second argument too. Is that because of how varargs are processed? What am I missing?
Output
Sizes: 8 4
Seg: 1111111122222222 33333333
Seg: 22222222 11111111
Seg: 33333333
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped
Command used
rm ./a.out ; g++ -m32 test.cpp ; ./a.out ; file a.out
-Wallto report all warnings.printflooks right to me, do you mean the thirdprintf?