I am trying to figure out the %sequence for short, unsigned long, long, unsigned long and long double.
This is a discussion on % sequence within the C Programming forums, part of the General Programming Boards category; I am trying to figure out the %sequence for short, unsigned long, long, unsigned long and long double....
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
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
From C99, since my knowledge of C is too deficient for me to figure it out myself offhandWhere 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".
Last edited by laserlight; 01-28-2008 at 12:14 PM.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
My PDF copy of ISO/IEC 9899:1999 "Programming languages - C", section 7.19.6.1 "The fprintf function".OK, but where exactly? Did you just have them memorized, or is there a website that I can go to check that stuff?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
>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
My best code is written with the delete key.
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.