I am trying to figure out the %sequence for short, unsigned long, long, unsigned long and long double.
Printable View
I am trying to figure out the %sequence for short, unsigned long, long, unsigned long and long double.
hmm... turns out my usual resource does not have all of these listed. Anyway, they should be:
short: hd
unsigned long: lu
unsigned long long: llu
long double: Lf
From C99, since my knowledge of C is too deficient for me to figure it out myself offhand :)Quote:
Where did you find those?
EDIT:
But that they were introduced in C99 could explain why cppreference.com does not list them. For %h the standard states that "the argument will have been promoted according to the integer promotions, but its value shall be converted to short int or unsigned short int before printing".
My PDF copy of ISO/IEC 9899:1999 "Programming languages - C", section 7.19.6.1 "The fprintf function".Quote:
OK, but where exactly? Did you just have them memorized, or is there a website that I can go to check that stuff?
>All the sources I've seen suggest that all ints (unsigned char,
>short, int, long) use %d and just get upgraded on their way in?
What sources? Except for long long, those are all C89 format specifiers, and unless you have a good reason, you should match the type as closely as you can.
For future reference, here's the C99 draft:
http://web.archive.org/web/200502070...c99-draft.html
And the C89 draft:
http://web.archive.org/web/200502070...c89-draft.html
Thanks, those should come in handy.
I was looking at the MSDN & an online Linux Man Pages site, but when I checked again, I found them. They're just not that easy to find or understand.
And arguments to printf (and all other variadic functions) are upgraded to integer and double for "short / char" and "float" respectively, but where "long" is different from "int", the int is not turned into a long, nor is "double" turned into a "long double", so using the correct sequence is important to ensure portability.
--
Mats