long long

I

Ioannis Vranos

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
 
R

Régis Troadec

Ioannis Vranos said:
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
 
I

Ioannis Vranos

Régis Troadec said:
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
 
M

Martin Ambuhl

Ioannis said:
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
 
K

Keith Thompson

Ioannis Vranos said:
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.
 
R

Régis Troadec

Ioannis Vranos said:
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
 
I

Ioannis Vranos

Keith Thompson said:
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 <[email protected]>
*
* 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
 
R

Régis Troadec

Ioannis Vranos said:
[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
 
C

CBFalconer

Ioannis said:
.... 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

Ioannis Vranos

CBFalconer said:
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
 
I

Ioannis Vranos

Régis Troadec said:
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
 
I

Irrwahn Grausewitz

Ioannis Vranos said:
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
 
J

Joe Wright

Ioannis said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top