Hi All,
I wrote this tiny code:
#include <stdio.h>
int main() {
size_t temp;
temp = 100;
printf("lld=%lld, ld=%ld, u=%u\n", temp, temp, temp);
return 0;
}
I am running this on a i386 GNU/Linux machine with gcc version 4.1.1 20070105 (Red Hat 4.1.1-52). This is the output that I got:
lld=429496729700, ld=100, u=7993461
I can understand that the first (lld
) was printed as garbage because the printf
tries to print 8 bytes (for signed long long
as signified by lld
) when only 4 bytes are available from variable temp
.
But, I fail to understand why the last identifier, u
is getting printed as garbage - whereas, in my understanding this is the closest applicable identifier for size_t
.
Here I have assumed that size_t
is unsigned int
(which is signed 4 bytes for my i386).
Now, I did a little tweaking with the printf
line:
...
printf("ld=%ld, u=%u, lld=%lld\n", temp, temp, temp);
...
and I have a perfectly fine answer (except the lld
part).
ld=100, u=100, lld=34331653576851556
Can someone please help me in understanding what exactly am I missing here?
Thanks a lot for any help!
[side note: I tried switching optimization using gcc -O[0,2]
tag on/off without any difference in the observation.]