[cfe-dev] Question about '<limits.h>' and availability of 'LLONG_MAX'
Dimitry Andric via cfe-dev
cfe-dev at lists.llvm.org
Mon May 8 14:56:41 PDT 2017
On 8 May 2017, at 17:02, Martin J. O'Riordan via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> 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.
You are incorrect there. For C sources, recent versions of clang
default to -std=gnu11 (except on PS4), and before that, the default was
always -std=gnu99. Under both, long long is available.
For C++, clang defaults to -std=gnu++98 (except again on PS4), and that
might be giving you grief. AFAIK C++98 does not officially know about
long long.
> 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
Does __STRICT_ANSI__ make any sense in regard to C++11 or higher?
-Dimitry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170508/06b98a3d/attachment.sig>
More information about the cfe-dev
mailing list