format specifier for long long ints....

Discussion in 'C Programming' started by Ray Dillinger, Mar 26, 2006.

  1. 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);
    }
     
    Ray Dillinger, Mar 26, 2006
    #1
    1. Advertising

  2. Ray Dillinger

    Jordan Abel Guest

    On 2006-03-26, Ray Dillinger <> wrote:
    >
    > 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.


    Your version of glibc does not support this conversion specifier. You
    need to upgrade.
     
    Jordan Abel, Mar 26, 2006
    #2
    1. Advertising

  3. Ray Dillinger

    santosh Guest

    Ray Dillinger wrote:
    > 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);
    > }


    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.
     
    santosh, Mar 26, 2006
    #3
  4. Ray Dillinger

    Cesar Rabak Guest

    Ray Dillinger escreveu:
    >
    > 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);
    > }
    >

    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
     
    Cesar Rabak, Mar 27, 2006
    #4
  5. Cesar Rabak <> writes:
    > Ray Dillinger escreveu:

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

    > 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.


    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) <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.
     
    Keith Thompson, Mar 27, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=
    Replies:
    1
    Views:
    495
    =?Utf-8?B?UGF1bA==?=
    Feb 1, 2005
  2. Replies:
    3
    Views:
    609
    Mark P
    Apr 3, 2005
  3. Chris N. Hinds

    unions with long long ints and doubles?

    Chris N. Hinds, Sep 30, 2003, in forum: C Programming
    Replies:
    3
    Views:
    437
    Barry Schwarz
    Oct 2, 2003
  4. Skybuck Flying

    ints ints ints and ints

    Skybuck Flying, Jul 8, 2004, in forum: C Programming
    Replies:
    24
    Views:
    871
    Jack Klein
    Jul 10, 2004
  5. David Geering

    longs, long longs, short short long ints . . . huh?!

    David Geering, Jan 8, 2007, in forum: C Programming
    Replies:
    15
    Views:
    595
    Keith Thompson
    Jan 11, 2007
Loading...

Share This Page