This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bamboozled by long long


Your data types are not matching your formats, a %lX expects a long, not a
long long.

Do this:

unsigned long long k=1;
unsigned int i = 4;
printf("The values are i: %d, , k: %lX, i+k: %lX \n", i, (long)k,
       (long)(i+k));
k = k + i;
printf("The values are i: %d, , k: %lX, i+k: %lX \n", i, (long)k,
       (long)(i+k));

That'll fix the problem.  If you have an appropriately modified/enhanced
"standard" C library, you may be able to do this...

unsigned long long k=1;
unsigned int i = 4;
printf("The values are i: %d, , k: %llX, i+k: %llX \n", i,k , i+k);
k = k + i;
printf("The values are i: %d, , k: %llX, i+k: %llX \n", i,k , i+k);

...or this...

unsigned long long k=1;
unsigned int i = 4;
printf("The values are i: %d, , k: %LX, i+k: %LX \n", i,k , i+k);
k = k + i;
printf("The values are i: %d, , k: %LX, i+k: %LX \n", i,k , i+k);

...depending on the extension (or convention for long long) used.

--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]