Connecting Tech Pros Worldwide Forums | Help | Site Map

format specifier for long long ints....

Ray Dillinger
Guest
 
Posts: n/a
#1: Mar 26 '06

Hi.

I'm using GCC on a SuSE Linux distribution, and the following program
doesn't work the way I expect. I'm using the conversion specifier for
long long integers that's in the man pages, but what's coming out is
interpreting the lowest few bytes of the long long int as an ordinary
integer. Other tests reveal that the full width is being preserved and
used in calculations - it's just output that seems broken. I must have
some misconfiguration somewhere, but I can't figure out what it is.
Has anyone else run up against this? Does anyone know how to fix it?

Thanks in advance,
Ray


#include <stdio.h>
main()
{
long long int foo = 10000000001LL;
printf("%lld\n", foo);
}


Jordan Abel
Guest
 
Posts: n/a
#2: Mar 26 '06

re: format specifier for long long ints....


On 2006-03-26, Ray Dillinger <bear@sonic.net> wrote:[color=blue]
>
> Hi.
>
> I'm using GCC on a SuSE Linux distribution, and the following program
> doesn't work the way I expect. I'm using the conversion specifier for
> long long integers that's in the man pages, but what's coming out is
> interpreting the lowest few bytes of the long long int as an ordinary
> integer. Other tests reveal that the full width is being preserved and
> used in calculations - it's just output that seems broken.[/color]

Your version of glibc does not support this conversion specifier. You
need to upgrade.
santosh
Guest
 
Posts: n/a
#3: Mar 26 '06

re: format specifier for long long ints....


Ray Dillinger wrote:[color=blue]
> Hi.
>
> I'm using GCC on a SuSE Linux distribution, and the following program
> doesn't work the way I expect. I'm using the conversion specifier for
> long long integers that's in the man pages, but what's coming out is
> interpreting the lowest few bytes of the long long int as an ordinary
> integer. Other tests reveal that the full width is being preserved and
> used in calculations - it's just output that seems broken. I must have
> some misconfiguration somewhere, but I can't figure out what it is.
> Has anyone else run up against this? Does anyone know how to fix it?
>
> Thanks in advance,
> Ray
>
>
> #include <stdio.h>
> main()
> {
> long long int foo = 10000000001LL;
> printf("%lld\n", foo);
> }[/color]

This is probably a issue of your C library (glibc?). Upgrade to your
latest gcc and C library version and try agian. Your code is correct,
(though not strictly C99 conforming), and should produce the expected
output with a C99 compliant compiler and standard library.

Cesar Rabak
Guest
 
Posts: n/a
#4: Mar 27 '06

re: format specifier for long long ints....


Ray Dillinger escreveu:[color=blue]
>
> Hi.
>
> I'm using GCC on a SuSE Linux distribution, and the following program
> doesn't work the way I expect. I'm using the conversion specifier for
> long long integers that's in the man pages, but what's coming out is
> interpreting the lowest few bytes of the long long int as an ordinary
> integer. Other tests reveal that the full width is being preserved and
> used in calculations - it's just output that seems broken. I must have
> some misconfiguration somewhere, but I can't figure out what it is.
> Has anyone else run up against this? Does anyone know how to fix it?
>
> Thanks in advance,
> Ray
>
>
> #include <stdio.h>
> main()
> {
> long long int foo = 10000000001LL;
> printf("%lld\n", foo);
> }
>[/color]
In a Mandriva 2006 Linux with gcc 4.0.3 your code compiled gives:
$ ./a.out
10000000001

which I believe is what you expect.

As a double check, I attempted:

$ gcc-3.3.6 -o a-3.3.6 suse.c
$ ./a-3.3.6
10000000001
$ gcc-2.96 -o a-2.96 suse.c
$ ./a-2.96
10000000001

where gcc-?-? are respective older versions.

HTH

--
Cesar Rabak


Keith Thompson
Guest
 
Posts: n/a
#5: Mar 27 '06

re: format specifier for long long ints....


Cesar Rabak <csrabak@yahoo.com.br> writes:[color=blue]
> Ray Dillinger escreveu:[/color]
[...][color=blue][color=green]
>> #include <stdio.h>
>> main()
>> {
>> long long int foo = 10000000001LL;
>> printf("%lld\n", foo); }
>>[/color]
> In a Mandriva 2006 Linux with gcc 4.0.3 your code compiled gives:
> $ ./a.out
> 10000000001
>
> which I believe is what you expect.
>
> As a double check, I attempted:
>
> $ gcc-3.3.6 -o a-3.3.6 suse.c
> $ ./a-3.3.6
> 10000000001
> $ gcc-2.96 -o a-2.96 suse.c
> $ ./a-2.96
> 10000000001
>
> where gcc-?-? are respective older versions.[/color]

gcc is a compiler, not a complete implementation. It typically uses
whatever runtime library is provided by the OS. On Linux, that's
generally glibc; on other systems, it's likely to be something else.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Closed Thread