Bamboozled by long long

Leo Przybylski leop@engr.arizona.edu
Fri Jul 19 14:22:00 GMT 2002


Doesn't make the code very portable does it?

-Leo

On Fri, 2002-07-19 at 12:14, John Love-Jensen wrote:
> 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
> 



More information about the Gcc-help mailing list