Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

How to print 64-bit integer in GCC 4.4.1?

$
0
0

I am using Code::Blocks with GCC 4.4.1 and I seem to be unable to print 64-bit signed integers from my C-code.

This code:

long long longint;

longint = 0x1BCDEFABCDEFCDEF; /* 2003520930423229935 */
printf("Sizeof: %d-bit\n", sizeof(longint) * 8);     /* Correct */
printf("%llx\n", longint);                           /* Incorrect */
printf("%x%x\n", *(((int*)(&longint))+1), longint);  /* Correct */
printf("%lld\n", longint);                           /* Incorrect */ 

Produces output:

Sizeof: 64-bit
cdefcdef
1bcdefabcdefcdef
-839922193

64-bit arithmetic seems to work correctly:

longint -= 0x1000000000000000;
printf("%x%x\n", *(((int*)(&longint))+1), longint);

Gives:

bcdefabcdefcdef

Am I missing something?


Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>