Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can one printf() in C not print two 64-bit values at the same time?

Tags:

c

printf

I am working on a 32-bit system. When I try to print more than one 64 bit value in a single printf, then it cannot print any further (i.e. 2nd, 3rd, ...) variable values.

example:

uint64_t a = 0x12345678;
uint64_t b = 0x87654321;
uint64_t c = 0x11111111;

printf("a is %llx & b is %llx & c is %llx",a,b,c);

Why can this printf not print all values?

I am modifying my question

printf("a is %x & b is %llx & c is %llx",a,b,c);

by doing this result is : a is 12345678 & b is 8765432100000000 & c is 1111111100000000

if i am not printing a's value properly then why other's value's are gona change??

like image 523
Jeegar Patel Avatar asked Jul 27 '11 20:07

Jeegar Patel


1 Answers

You should use the macros defined in <inttypes.h>

printf("a is %"PRIx64" & b is %"PRIx64" & c is %"PRIx64"\n",a,b,c);

It is ugly as hell but it's portable. This was introduced in C99, so you need a C99 compliant compiler.

like image 97
Vinicius Kamakura Avatar answered Sep 19 '22 06:09

Vinicius Kamakura