* Question about ULLONG_MAX
@ 2007-07-02 8:55 Holger Kiehl
2007-07-02 12:57 ` Stephen Kratzer
2007-07-02 18:55 ` Glynn Clements
0 siblings, 2 replies; 4+ messages in thread
From: Holger Kiehl @ 2007-07-02 8:55 UTC (permalink / raw)
To: linux-c-programming
Hello
When compiling the following program on a Fedora 6 x86_64 system:
#include <stdio.h>
#include <limits.h>
int
main(void)
{
(void)printf("%llu\n", ULLONG_MAX);
return 0;
}
Produces the following result:
cc longlong.c
longlong.c: In function 'main':
longlong.c:7: error: 'ULLONG_MAX' undeclared (first use in this function)
longlong.c:7: error: (Each undeclared identifier is reported only once
longlong.c:7: error: for each function it appears in.)
If I compile it with cc -std=c99 longlong.c it works.
Why is it necessary to specify -std=c99? If I use for example strtoull()
I do not need to set -std=c99.
Compiling the above on AIX compiles and runs without problems. Also
on an older Solaris 8 system using gcc (3.3.2) it compiles and runs
straight out of the box.
If I want to use ULLONG_MAX how can I do this in a portable way so it
compiles on different systems?
Thanks,
Holger
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Question about ULLONG_MAX
2007-07-02 8:55 Question about ULLONG_MAX Holger Kiehl
@ 2007-07-02 12:57 ` Stephen Kratzer
2007-07-02 18:55 ` Glynn Clements
1 sibling, 0 replies; 4+ messages in thread
From: Stephen Kratzer @ 2007-07-02 12:57 UTC (permalink / raw)
To: Holger Kiehl; +Cc: linux-c-programming
From limits.h,
# ifdef __USE_ISOC99
/* Minimum and maximum values a `signed long long int' can hold. */
# define LLONG_MAX 9223372036854775807LL
# define LLONG_MIN (-LLONG_MAX - 1LL)
/* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */
# define ULLONG_MAX 18446744073709551615ULL
# endif /* ISO C99 */
/* The <limits.h> files in some gcc versions don't define LLONG_MIN,
LLONG_MAX, and ULLONG_MAX. Instead only the values gcc defined for
ages are available. */
#if defined __USE_ISOC99 && defined __GNUC__
# ifndef LLONG_MIN
# define LLONG_MIN (-LLONG_MAX-1)
# endif
# ifndef LLONG_MAX
# define LLONG_MAX __LONG_LONG_MAX__
# endif
# ifndef ULLONG_MAX
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
# endif
#endif
On Monday 02 July 2007 04:55:00 Holger Kiehl wrote:
> Hello
>
> When compiling the following program on a Fedora 6 x86_64 system:
>
> #include <stdio.h>
> #include <limits.h>
>
> int
> main(void)
> {
> (void)printf("%llu\n", ULLONG_MAX);
>
> return 0;
> }
>
> Produces the following result:
>
> cc longlong.c
> longlong.c: In function 'main':
> longlong.c:7: error: 'ULLONG_MAX' undeclared (first use in this
> function) longlong.c:7: error: (Each undeclared identifier is reported only
> once longlong.c:7: error: for each function it appears in.)
>
> If I compile it with cc -std=c99 longlong.c it works.
>
> Why is it necessary to specify -std=c99? If I use for example strtoull()
> I do not need to set -std=c99.
>
> Compiling the above on AIX compiles and runs without problems. Also
> on an older Solaris 8 system using gcc (3.3.2) it compiles and runs
> straight out of the box.
>
> If I want to use ULLONG_MAX how can I do this in a portable way so it
> compiles on different systems?
>
> Thanks,
> Holger
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-c-programming" in the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Question about ULLONG_MAX
2007-07-02 8:55 Question about ULLONG_MAX Holger Kiehl
2007-07-02 12:57 ` Stephen Kratzer
@ 2007-07-02 18:55 ` Glynn Clements
2007-07-02 20:39 ` Holger Kiehl
1 sibling, 1 reply; 4+ messages in thread
From: Glynn Clements @ 2007-07-02 18:55 UTC (permalink / raw)
To: Holger Kiehl; +Cc: linux-c-programming
Holger Kiehl wrote:
> Hello
>
> When compiling the following program on a Fedora 6 x86_64 system:
>
> #include <stdio.h>
> #include <limits.h>
>
> int
> main(void)
> {
> (void)printf("%llu\n", ULLONG_MAX);
>
> return 0;
> }
>
> Produces the following result:
>
> cc longlong.c
> longlong.c: In function 'main':
> longlong.c:7: error: 'ULLONG_MAX' undeclared (first use in this function)
> longlong.c:7: error: (Each undeclared identifier is reported only once
> longlong.c:7: error: for each function it appears in.)
>
> If I compile it with cc -std=c99 longlong.c it works.
>
> Why is it necessary to specify -std=c99? If I use for example strtoull()
> I do not need to set -std=c99.
The declaration of strtoull() is enabled by __USE_MISC:
#if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
If you use "-ansi -Wall", you'll get a warning due to the implicit
declaration of strtoull().
Bear in mind that a missing declaration only results in a warning,
while a missing macro is an error (as the symbol won't exist in any
library).
> Compiling the above on AIX compiles and runs without problems. Also
> on an older Solaris 8 system using gcc (3.3.2) it compiles and runs
> straight out of the box.
>
> If I want to use ULLONG_MAX how can I do this in a portable way so it
> compiles on different systems?
You need to explicitly enable C99 support; "long long" isn't in C89,
so you shouldn't assume that it will be available when using the
default compilation settings.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Question about ULLONG_MAX
2007-07-02 18:55 ` Glynn Clements
@ 2007-07-02 20:39 ` Holger Kiehl
0 siblings, 0 replies; 4+ messages in thread
From: Holger Kiehl @ 2007-07-02 20:39 UTC (permalink / raw)
To: Glynn Clements; +Cc: linux-c-programming
On Mon, 2 Jul 2007, Glynn Clements wrote:
>
> Holger Kiehl wrote:
>
>> Compiling the above on AIX compiles and runs without problems. Also
>> on an older Solaris 8 system using gcc (3.3.2) it compiles and runs
>> straight out of the box.
>>
>> If I want to use ULLONG_MAX how can I do this in a portable way so it
>> compiles on different systems?
>
> You need to explicitly enable C99 support; "long long" isn't in C89,
> so you shouldn't assume that it will be available when using the
> default compilation settings.
>
You are right. Enabling C99 support explicitly is the better solution.
Thanks,
Holger
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-07-02 20:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-02 8:55 Question about ULLONG_MAX Holger Kiehl
2007-07-02 12:57 ` Stephen Kratzer
2007-07-02 18:55 ` Glynn Clements
2007-07-02 20:39 ` Holger Kiehl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).