printf format specifiers
John Love-Jensen
eljay@adobe.com
Mon Oct 21 06:33:00 GMT 2002
Hi Steve,
Let's assume that char is 8-bit, short is 16-bit, int is 32-bit, long is
64-bit, and long long is 128-bit.
When you put a char or short on the stack, they are expanded to int.
The int represents the platform's natural, native size... sometimes called a
"word". Note: "word" is platform dependent!
So if you had these:
char c = '1'; // 0x31, 8-bit, a quarter-word
short s = 0x1122; // 16-bit, a half-word
int i = 0x33445566; // 32-bit, a word
long d = 0x9988776655443322; // 64-bit, a double-word
long long q = 0xFFEEDDCCBBAA99887766554433221100; // 128-bit, a quad-word
If you do this:
printf("%d %d %d %ld %lld", c, s, i, d, q);
The stack will look like this:
02100010 : pointer to "%d %d %d %ld %lld"
00000031 : c, expanded to word-size
00001122 : s, expanded to word-size
33445566 : i
99887766 : d's MSW
55443322 : d's LSW
FFEEDDCC : q's MSW
BBAA9988 : q's 2SW
77665544 : q's 3SW
33221100 : q's LSW
The fictional platform presented is a big-endian platform. Ala Motorola
680x0.
--Eljay
More information about the Gcc-help
mailing list