long long

Discussion in 'C Programming' started by Ioannis Vranos, Apr 16, 2004.

  1. Hi all,

    Is long long supposed to be supported in all C99 implementations?If yes is
    it supposed to be 64 bit at least? GCC says that it supports long long, but
    i got this:


    #include <stdio.h>
    #include <limits.h>

    int main()
    {
    printf("Maximum value for long long: %lld\n", LLONG_MAX);
    printf("Maximum value for long: %ld\n", LONG_MAX);

    }


    C:\c>\mingw\bin\gcc -v
    Reading specs from /mingw/bin/../lib/gcc-lib/mingw32/3.3.1/specs
    Configured with:
    .../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
    mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --en
    able
    -languages=c,c++,f77,objc,ada,java --disable-win32-registry --disable-shared
    --e
    nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enabl
    e-ja
    va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchr
    oniz
    ation
    Thread model: win32
    gcc version 3.3.1 (mingw special 20030804-1)


    C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    temp.c: In function `main':
    temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    temp.c:6: error: (Each undeclared identifier is reported only once
    temp.c:6: error: for each function it appears in.)

    C:\c>


    Any ideas?






    Regards,

    Ioannis Vranos
     
    Ioannis Vranos, Apr 16, 2004
    #1
    1. Advertising

  2. "Ioannis Vranos" <> a écrit dans le message de
    news:c5phu8$n45$...
    > Hi all,


    Hi,

    >
    > Is long long supposed to be supported in all C99 implementations?If yes is
    > it supposed to be 64 bit at least? GCC says that it supports long long,

    but
    > i got this:


    Yes.

    >
    > #include <stdio.h>
    > #include <limits.h>
    >
    > int main()


    int main(void)

    > {
    > printf("Maximum value for long long: %lld\n", LLONG_MAX);
    > printf("Maximum value for long: %ld\n", LONG_MAX);
    >
    > }
    >


    Your program looks true regarding C99.

    <>

    > Thread model: win32
    > gcc version 3.3.1 (mingw special 20030804-1)
    >
    >
    > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    > temp.c: In function `main':
    > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    > temp.c:6: error: (Each undeclared identifier is reported only once
    > temp.c:6: error: for each function it appears in.)
    >
    > C:\c>
    >
    >
    > Any ideas?
    >


    I compiled it properly with gcc 3.3.1 (cygwin) with the same options but the
    compilation did'nt succeed with Dev-C++ 4.9.8.0 (uses mingw version of gcc
    3.2) and I got the same error. It appears it's a bug of the mingw gcc
    portage.
    I don't know if it has already been reported. You'll maybe find much more
    informations at www.mingw.org.


    Regis

    >
    >
    >
    >
    > Regards,
    >
    > Ioannis Vranos
    >
    >
    >
     
    Régis Troadec, Apr 16, 2004
    #2
    1. Advertising

  3. "Régis Troadec" <> wrote in message
    news:c5plfa$bdj$...
    >
    > I compiled it properly with gcc 3.3.1 (cygwin) with the same options but

    the
    > compilation did'nt succeed with Dev-C++ 4.9.8.0 (uses mingw version of gcc
    > 3.2) and I got the same error. It appears it's a bug of the mingw gcc
    > portage.



    Can you provide me with the results at least, so as to not remain with the
    curiosity? :)






    Ioannis Vranos
     
    Ioannis Vranos, Apr 16, 2004
    #3
  4. Ioannis Vranos wrote:

    > Hi all,
    >
    > Is long long supposed to be supported in all C99 implementations?If yes is
    > it supposed to be 64 bit at least? GCC says that it supports long long, but
    > i got this:
    >
    >
    > #include <stdio.h>
    > #include <limits.h>
    >
    > int main()
    > {
    > printf("Maximum value for long long: %lld\n", LLONG_MAX);
    > printf("Maximum value for long: %ld\n", LONG_MAX);


    > gcc version 3.3.1 (mingw special 20030804-1)


    > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    > temp.c: In function `main':
    > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    > temp.c:6: error: (Each undeclared identifier is reported only once
    > temp.c:6: error: for each function it appears in.)


    I don't remember if 3.3.1 had a header problem, but 3.3.2 gives me:

    Maximum value for long long: 9223372036854775807
    Maximum value for long: 2147483647
     
    Martin Ambuhl, Apr 16, 2004
    #4
  5. "Ioannis Vranos" <> writes:
    > Hi all,
    >
    > Is long long supposed to be supported in all C99 implementations?If yes is
    > it supposed to be 64 bit at least?


    Yes, and yes.

    > GCC says that it supports long long, but i got this:
    >
    >
    > #include <stdio.h>
    > #include <limits.h>
    >
    > int main()
    > {
    > printf("Maximum value for long long: %lld\n", LLONG_MAX);
    > printf("Maximum value for long: %ld\n", LONG_MAX);
    >
    > }

    [...]
    > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    > temp.c: In function `main':
    > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    > temp.c:6: error: (Each undeclared identifier is reported only once
    > temp.c:6: error: for each function it appears in.)


    A conforming implementation consists of both the compiler and the
    library (including header files). Apparently your compiler supports
    the long long thype, probably correctly, but your <limits.h> header
    doesn't define LLONG_MAX (and I'll bet your library's printf() doesn't
    support "%lld").

    On at least one system I have access to (Red Hat 9, gcc 3.2.2), this
    works correctly.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Apr 16, 2004
    #5
  6. "Ioannis Vranos" <> a écrit dans le message de
    news:c5ploo$107k$...
    > "Régis Troadec" <> wrote in message
    > news:c5plfa$bdj$...
    > >
    > > I compiled it properly with gcc 3.3.1 (cygwin) with the same options but

    > the
    > > compilation did'nt succeed with Dev-C++ 4.9.8.0 (uses mingw version of

    gcc
    > > 3.2) and I got the same error. It appears it's a bug of the mingw gcc
    > > portage.

    >
    >
    > Can you provide me with the results at least, so as to not remain with the
    > curiosity? :)


    Yes.

    <cygwin console>

    regis~
    $ ls
    a.out dev_C dev_CPP tutu.c

    regis~
    $ cat tutu.c
    #include <stdio.h>
    #include <limits.h>

    int main(void)
    {
    printf("Max of long long is %lld",LLONG_MAX);
    printf("Max of long is %ld", LONG_MAX);
    }



    regis~
    $ gcc --version
    gcc (GCC) 3.3.1 (cygming special)
    Copyright (C) 2003 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.

    regis~
    $ gcc -std=c99 -pedantic -errors -Wall -O3 -c tutu.c

    regis~
    $ ls
    a.out dev_C dev_CPP tutu.c tutu.o

    regis~
    $ gcc tutu.o -o tutu

    regis~
    $ ./tutu
    Max of long long is 9223372036854775807Max of long is 2147483647

    </cygwin console>


    Regis

    >
    >
    >
    >
    >
    >
    > Ioannis Vranos
    >
     
    Régis Troadec, Apr 16, 2004
    #6
  7. "Keith Thompson" <> wrote in message
    news:...
    >
    > A conforming implementation consists of both the compiler and the
    > library (including header files). Apparently your compiler supports
    > the long long thype, probably correctly, but your <limits.h> header
    > doesn't define LLONG_MAX (and I'll bet your library's printf() doesn't
    > support "%lld").
    >
    > On at least one system I have access to (Red Hat 9, gcc 3.2.2), this
    > works correctly.



    Actually limits.h contains:

    /*
    * limits.h
    *
    * Defines constants for the sizes of integral types.
    *
    * NOTE: GCC should supply a version of this header and it should be safe to
    * use that version instead of this one (maybe safer).
    *
    * This file is part of the Mingw32 package.
    *
    * Contributors:
    * Created by Colin Peters <-u.ac.jp>
    *
    * THIS SOFTWARE IS NOT COPYRIGHTED
    *
    * This source code is offered for use in the public domain. You may
    * use, modify or distribute it freely.
    *
    * This code is distributed in the hope that it will be useful but
    * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
    * DISCLAIMED. This includes but is not limited to warranties of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    *
    * $Revision: 1.3 $
    * $Author: dannysmith $
    * $Date: 2001/11/29 04:26:33 $
    *
    */

    #ifndef _LIMITS_H_
    #define _LIMITS_H_

    /* All the headers include this file. */
    #include <_mingw.h>

    /*
    * File system limits
    *
    * TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the
    * same as FILENAME_MAX and FOPEN_MAX from stdio.h?
    * NOTE: Apparently the actual size of PATH_MAX is 260, but a space is
    * required for the NUL. TODO: Test?
    */
    #define PATH_MAX (259)

    /*
    * Characteristics of the char data type.
    *
    * TODO: Is MB_LEN_MAX correct?
    */
    #define CHAR_BIT 8
    #define MB_LEN_MAX 2

    #define SCHAR_MIN (-128)
    #define SCHAR_MAX 127

    #define UCHAR_MAX 255

    /* TODO: Is this safe? I think it might just be testing the preprocessor,
    * not the compiler itself... */
    #if ('\x80' < 0)
    #define CHAR_MIN SCHAR_MIN
    #define CHAR_MAX SCHAR_MAX
    #else
    #define CHAR_MIN 0
    #define CHAR_MAX UCHAR_MAX
    #endif

    /*
    * Maximum and minimum values for ints.
    */
    #define INT_MAX 2147483647
    #define INT_MIN (-INT_MAX-1)

    #define UINT_MAX 0xffffffff

    /*
    * Maximum and minimum values for shorts.
    */
    #define SHRT_MAX 32767
    #define SHRT_MIN (-SHRT_MAX-1)

    #define USHRT_MAX 0xffff

    /*
    * Maximum and minimum values for longs and unsigned longs.
    *
    * TODO: This is not correct for Alphas, which have 64 bit longs.
    */
    #define LONG_MAX 2147483647L

    #define LONG_MIN (-LONG_MAX-1)

    #define ULONG_MAX 0xffffffffUL


    /*
    * The GNU C compiler also allows 'long long int'
    */
    #if !defined(__STRICT_ANSI__) && defined(__GNUC__)

    #define LONG_LONG_MAX 9223372036854775807LL
    #define LONG_LONG_MIN (-LONG_LONG_MAX-1)

    #define ULONG_LONG_MAX (2ULL * LONG_LONG_MAX + 1)

    /* ISO C9x macro names */
    #define LLONG_MAX LONG_LONG_MAX
    #define LLONG_MIN LONG_LONG_MIN
    #define ULLONG_MAX ULONG_LONG_MAX

    #endif /* Not Strict ANSI and GNU C compiler */


    #endif /* not _LIMITS_H_ */






    Ioannis Vranos
     
    Ioannis Vranos, Apr 16, 2004
    #7
  8. "Ioannis Vranos" <> a écrit dans le message de
    news:c5pnpq$14lc$...
    > "Keith Thompson" <> wrote in message
    > news:...
    > >


    [snipped]

    >> /*

    > * The GNU C compiler also allows 'long long int'
    > */
    > #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
    >
    > #define LONG_LONG_MAX 9223372036854775807LL
    > #define LONG_LONG_MIN (-LONG_LONG_MAX-1)
    >
    > #define ULONG_LONG_MAX (2ULL * LONG_LONG_MAX + 1)
    >
    > /* ISO C9x macro names */
    > #define LLONG_MAX LONG_LONG_MAX
    > #define LLONG_MIN LONG_LONG_MIN
    > #define ULLONG_MAX ULONG_LONG_MAX
    >
    > #endif /* Not Strict ANSI and GNU C compiler */
    >
    >
    >


    Now you have your answer, it's not a bug in itself :)
    It's just that your header file isn't C99 ready yet.
    __STRICT__ANSI__ is defined if you use -ansi, -std=cXX options with gcc.

    See the difference :

    <piece of my limits.h>

    /* limits.h

    Copyright 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.

    This file is part of Cygwin.

    This software is a copyrighted work licensed under the terms of the
    Cygwin license. Please consult the file "CYGWIN_LICENSE" for
    details. */

    /*..........*/

    /* Minimum and maximum values a `signed long long int' can hold. */
    #ifndef __LONG_LONG_MAX__
    #define __LONG_LONG_MAX__ 9223372036854775807LL
    #endif

    #if defined (__GNU_LIBRARY__) ? defined (__USE_GNU) : !defined
    (__STRICT_ANSI__)

    #undef LONG_LONG_MIN
    #define LONG_LONG_MIN (-LONG_LONG_MAX-1)
    #undef LONG_LONG_MAX
    #define LONG_LONG_MAX __LONG_LONG_MAX__

    /* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */
    #undef ULONG_LONG_MAX
    #define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
    #endif

    #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    /* Minimum and maximum values a `signed long long int' can hold. */
    #undef LLONG_MIN
    #define LLONG_MIN (-LLONG_MAX-1)
    #undef LLONG_MAX
    #define LLONG_MAX __LONG_LONG_MAX__

    </piece of my limits.h>

    Regis

    >
    > Ioannis Vranos
    >
     
    Régis Troadec, Apr 17, 2004
    #8
  9. Ioannis Vranos

    CBFalconer Guest

    Ioannis Vranos wrote:
    >

    .... snip ...
    >
    > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    > temp.c: In function `main':
    > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    > temp.c:6: error: (Each undeclared identifier is reported only once
    > temp.c:6: error: for each function it appears in.)


    Works fine here on gcc 3.2.1. Your gcc is misinstalled.

    c:\c\junk>gcc -std=c99 -pedantic -Wall longlong.c

    c:\c\junk>.\a
    Maximum value for long long: 9223372036854775807
    Maximum value for long: 2147483647

    c:\c\junk>cat longlong.c
    #include <stdio.h>
    #include <limits.h>

    int main()
    {
    printf("Maximum value for long long: %lld\n", LLONG_MAX);
    printf("Maximum value for long: %ld\n", LONG_MAX);
    }

    --
    "I'm a war president. I make decisions here in the Oval Office
    in foreign policy matters with war on my mind." - Bush
     
    CBFalconer, Apr 17, 2004
    #9
  10. "CBFalconer" <> wrote in message
    news:...
    > Ioannis Vranos wrote:
    > >

    > ... snip ...
    > >
    > > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    > > temp.c: In function `main':
    > > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    > > temp.c:6: error: (Each undeclared identifier is reported only once
    > > temp.c:6: error: for each function it appears in.)

    >
    > Works fine here on gcc 3.2.1. Your gcc is misinstalled.



    Wrong diagnosis. My gcc is properly installed. It is f***** *p.






    Ioannis Vranos
     
    Ioannis Vranos, Apr 17, 2004
    #10
  11. "Régis Troadec" <> wrote in message
    news:c5pn0k$g81$...
    >
    > $ ./tutu
    > Max of long long is 9223372036854775807Max of long is 2147483647



    Thanks.






    Regards,

    Ioannis Vranos
     
    Ioannis Vranos, Apr 17, 2004
    #11
  12. "Régis Troadec" <> wrote in message
    news:c5pn0k$g81$...
    >
    > Max of long long is 9223372036854775807Max of long is 2147483647



    I just downloaded and installed djgpp, which it works:


    C:\c>more temp.c
    #include <stdio.h>
    #include <limits.h>

    int main()
    {
    printf("%lld\n", LLONG_MAX);
    }

    C:\c>gcc -std=c99 -pedantic-errors temp.c -o temp

    C:\c>temp
    9223372036854775807

    C:\c>






    Ioannis Vranos
     
    Ioannis Vranos, Apr 17, 2004
    #12
  13. "Ioannis Vranos" <> wrote:
    >"CBFalconer" <> wrote in message
    >news:...
    >> Ioannis Vranos wrote:
    >> >

    >> ... snip ...
    >> >
    >> > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    >> > temp.c: In function `main':
    >> > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)

    >>
    >> Works fine here on gcc 3.2.1. Your gcc is misinstalled.

    >
    >Wrong diagnosis. My gcc is properly installed. It is f***** *p.


    Well, the compiler itself is fine, AFAICT after some tests. It's
    the library that comes with mingw that's broken, as you can see
    when you compile and run this program on this implementation:

    #include <stdio.h>
    int main( void )
    {
    unsigned long long ull = 0xDEADBEEF12345678ULL;
    printf( "%llX\n", ull );
    printf( "%llX\n", ull >> 32 );
    return 0;
    }


    Regards
    --
    Irrwahn Grausewitz ()
    welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
    clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
    clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
     
    Irrwahn Grausewitz, Apr 17, 2004
    #13
  14. Ioannis Vranos

    Joe Wright Guest

    Ioannis Vranos wrote:
    > Hi all,
    >
    > Is long long supposed to be supported in all C99 implementations?If yes is
    > it supposed to be 64 bit at least? GCC says that it supports long long, but
    > i got this:
    >
    >
    > #include <stdio.h>
    > #include <limits.h>
    >
    > int main()
    > {
    > printf("Maximum value for long long: %lld\n", LLONG_MAX);
    > printf("Maximum value for long: %ld\n", LONG_MAX);
    >
    > }
    >
    >
    > C:\c>\mingw\bin\gcc -v
    > Reading specs from /mingw/bin/../lib/gcc-lib/mingw32/3.3.1/specs
    > Configured with:
    > ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
    > mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --en
    > able
    > -languages=c,c++,f77,objc,ada,java --disable-win32-registry --disable-shared
    > --e
    > nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enabl
    > e-ja
    > va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchr
    > oniz
    > ation
    > Thread model: win32
    > gcc version 3.3.1 (mingw special 20030804-1)
    >
    >
    > C:\c>\mingw\bin\gcc -std=c99 -pedantic-errors -O3 -Wall temp.c -o temp
    > temp.c: In function `main':
    > temp.c:6: error: `LLONG_MAX' undeclared (first use in this function)
    > temp.c:6: error: (Each undeclared identifier is reported only once
    > temp.c:6: error: for each function it appears in.)
    >
    > C:\c>
    >
    >
    > Any ideas?
    >
    >
    >
    >
    >
    >
    > Regards,
    >
    > Ioannis Vranos
    >
    >
    >

    I've called this ll.c

    #include <stdio.h>
    #include <limits.h>

    int main()
    {
    printf("Maximum value for long long: %lld\n", LLONG_MAX);
    printf("Maximum value for long: %ld\n", LONG_MAX);
    return 0; /* I added this for you. jww */
    }


    C:\work\c\clc>gcc -Wall -s -O2 ll.c -o ll.exe
    C:\work\c\clc>ll
    Maximum value for long long: 9223372036854775807
    Maximum value for long: 2147483647

    C:\work\c\clc>gcc -W -Wall -ansi -pedantic -s -O2 ll.c -o ll.exe
    ll.c: In function `main':
    ll.c:6: `LLONG_MAX' undeclared (first use in this function)
    ll.c:6: (Each undeclared identifier is reported only once
    ll.c:6: for each function it appears in.)
    ll.c:6: warning: ISO C89 does not support the `ll' printf length
    modifier

    C:\work\c\clc>gcc -v
    Reading specs from c:/djgpp/lib/gcc-lib/djgpp/3.1/specs
    Configured with: ../configure i586-pc-msdosdjgpp
    --prefix=/dev/env/DJDIR --disab
    le-nls
    Thread model: single
    gcc version 3.1

    C:\work\c\clc>gcc -std=c99 -pedantic-errors -Wall -O3 ll.c -o ll.exe
    compiles with no errors or warnings.


    --
    Joe Wright mailto:
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
     
    Joe Wright, Apr 17, 2004
    #14
    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. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    684
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,197
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    482
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    808
    Peter Nilsson
    Jan 15, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,811
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page