How to print 64-bit integer in GCC 4.4.1?
See if %I64d
helps you. %lld
is fine for long long int
but things get really different sometimes on Windows IDEs
This is OS dependent. If you're doing this on just about any GCC that uses GLIBC, then %llx works.
However if you are using mingw compiler, then this uses Microsoft libraries, and you need to look into their documentation.
This changes your program to:
longint = 0x1BCDEFABCDEFCDEFLL; /* 2003520930423229935 */
printf("Sizeof: %d-bit\n", sizeof(longint) * 8); /* Correct */
printf("%I64x\n", longint); /* Incorrect */
printf("%x%x\n", *(((int*)(&longint))+1), longint); /* Correct */
printf("%I64d\n", longint);
To (in C99 and up) portably print 64 bit integers, you should #include <inttypes.h>
and use the C99 macros PRIx64
and PRId64
. That would make your code;
printf("Sizeof: %d-bit\n", sizeof(longint) * 8);
printf("%" PRIx64 "\n", longint);
printf("%" PRId64 "\n", longint);
Edit: See this question for more examples.
longint = 0x1BCDEFABCDEFCDEF; /* 2003520930423229935 */ you can print as-
printf("%llx", longint);