Mail Archives: djgpp/2000/04/10/19:05:18
Robert S Whitlock wrote:
>Hello I'm trying to use printf() and family to print long long variables.
>But I don't know of any conversion spcifier thingie. Can anyone help me
>out?
The following code should answer your question.
#include <stdio.h>
int main(void)
{
long long ll = 0x123456789abcdefLL;
unsigned long long ull = 0x123456789abcdefULL;
printf("long long ll is %Ld, in hex this is 0x%Lx\n",
ll, (unsigned long long)ll);
printf("unsigned long long ull is %Lu, in hex this is 0x%Lx\n",
ull, ull);
return 0;
}
So, use the "L" modifier for long long type.
>If there is another data type that has increased range over the int type
>and is a "whole number" variable instead of a floating point, and you
>know the conversion specifier to that, that would be great too.
There is no other standard integral data type with an increased range.
If you are careful, and if you work on a platform, that is conformant
to the IEEE floating point standards, type double or type long double
might be useful and more portable to non gcc compilers (and to pre-C99
compilers). With type double, all integers up to 2^54 are guaranteed
to be exact floating point numbers.
--
Regards, Dieter
- Raw text -