I’m storing some unsigned long long values, but when I try to output them via printf or sprintf, I get garbage.
example:
unsigned long long uiTest = 2534ULL;
printf( "%llu
", uiTest );
uiTest = 12345678901234567890ULL;
printf( "%llu
", uiTest );
18446744073709551616
/example
output:
0
2874452364
/output
Any idea why?
To answer my own question:
Despite being able to handle unsigned long longs, the printf/sprintf support doesn’t seem to be there.
printf( "%llu
", 4294967296ULL );
will output 1. So basically it is truncating and rolling over.
I order to get the value I needed, I did a bitshift and output hex.
sprintf( szOutput, “%lx%08lx”, uiValue, uiValue>>32 );
So if you run into this, now you know.