In Windows, it is “%I64d”. In Linux and Solaris, it is “%lld”.
If I want to write cross-platform printfs that prints long long values: what is good way of doing so ?
long long ll;
printf(???, ll);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a couple of approaches.
You could write your code in C99-conforming fashion, and then supply system-specific hacks when the compiler-writers let you down. (Sadly, that’s rather common in C99.)
If one of your target systems has neglected to implement
<inttypes.h>or has in some other way fiendishly slacked off because some of the type features are optional, then you just need a system-specific#defineforPRId64(or whatever) on that system.The other approach is to pick something that’s currently always implemented as 64-bits and is supported by printf, and then cast. Not perfect but it will often do: