[cfe-dev] warnings about large negative integer values

Matthieu Monrocq matthieu.monrocq at gmail.com
Wed Feb 1 12:31:28 PST 2012


Le 1 février 2012 16:38, Mansour Moufid <mansourmoufid at gmail.com> a écrit :

> Hello,
>
> Clang is producing curious warnings about certain large (in magnitude)
> negative integer values.
>
> I have a.c:
>
>    #include <limits.h>
>    #include <stdio.h>
>    int main(void) {
>        long int x = -9223372036854775808L;
>        printf("%li\n", x);
>        printf("%li\n", LONG_MIN);
>        return 0;
>    }
>
> Running the compiled executable produces the two lines:
>
>    -9223372036854775808
>    -9223372036854775808
>
> but compiling produced the warning:
>
>    a.c:4:19: warning: integer constant is so large that it is unsigned
>        long int x = -9223372036854775808L;
>                      ^
>    1 warning generated.
>
> The preprocessor gives:
>
>    ...
>    # 3 "a.c" 2
>    int main(void) {
>        long int x = -9223372036854775808L;
>        printf("%li\n", x);
>        printf("%li\n", (-9223372036854775807L - 1L));
>        return 0;
>    }
>
> So obviously the warning is incorrect. Is there a reason that warning
> is produced here?
>
> Mansour
>

For what it's worth, gcc (4.3.2) is affected by the very same warning. It
seems bogus and is probably due to the fact that the 9223372036854775808L
would be too large for the type.

--Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120201/dd50b2d5/attachment.html>


More information about the cfe-dev mailing list