|
|
Pilcrow <pilcrow@xxxxxxx> writes:
> I have a fair understanding of perl, now I'm trying to learn C.
> I'm trying to use long long, with trouble. Here is demo code.
> I'm using the gcc that came with strawberry perl.
> Same output if I say %lld instead of %lli.
> Grateful for any help I can get.
>
> // demo.c
> #include <stdio.h>
> #include <limits.h>
> int main()
> {
> printf("%d\n",sizeof(long long));
> printf("%llu \n",ULLONG_MAX);
> printf("%lli \n",LLONG_MIN);
> printf("%lli \n",LLONG_MAX);
> printf("%lli to %lli \n",LLONG_MIN,LLONG_MAX);
> }
>
> Here is the output.
>
> C:\>gcc --version
> gcc (GCC) 3.4.5 (mingw special)
> Copyright (C) 2004 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is
> NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.
>
>
> C:\>gcc -std=c99, -Wall demo.c
>
> C:\>a
> 8
> 4294967295
> 0
> -1
> 0 to -2147483648
>
> C:\>
That looks like a C99 compiler using a printf that is not long long
aware. Out of interest try this:
#include <stdio.h>
#include <limits.h>
int main(void)
{
char b[100];
snprintf(b, sizeof b, "%llu\n", ULLONG_MAX);
printf("%s", b);
printf("%d\n",sizeof(long long));
printf("%llu\n",ULLONG_MAX);
}
On my (later) version, I get:
18446744073709551615
8
4294967295
I think this is well-known issue with MS C library, but I may be
misremembering that. (Searches...) Ah, yes it is well known:
http://www.mingw.org/MinGWiki/index.php/long%20long
--
Ben.
|
|