[cfe-dev] Question about '<limits.h>' and availability of 'LLONG_MAX'
Martin J. O'Riordan via cfe-dev
cfe-dev at lists.llvm.org
Mon May 8 08:02:41 PDT 2017
I was looking at an issue recently where a programmer was using 'LLONG_MAX'
in a program such as the following:
#include <limits.h>
int foo(long long x) { return x == LLONG_MAX; }
If this is a C program, then it compiles okay; but if it is a C++ program it
does not, though this was really simply fixed by adding '-std=c++11
-U__STRICT_ANSI__' to the options.
clang seems to default to a relaxed C90 if '-std=' is not used, so 'long
long' and 'LLONG_MAX' are available. Adding '-std=c90' results in a more
strict Standard violation error as expected.
But when compiled for C++ the equivalent relaxation does not happen and it
is an error even when '-std=' is not used
The test in '<limits.h>' (from 'clang/lib/Headers') is:
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
and I wonder would something like:
#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L ||
__cplusplus >= 201103L
be more consistent with how ISO Standards are enforced when '-std=' is not
used, and it would appear that this would align better with GCC too (though
GCC seems to also allow it when '-std=c++98' or '-std=c90' is selected which
I do not suggest 'clang' should follow).
Thanks,
MartinO
More information about the cfe-dev
mailing list