[cfe-dev] warnings about large negative integer values

Eli Friedman eli.friedman at gmail.com
Wed Feb 1 12:33:36 PST 2012

On Wed, Feb 1, 2012 at 7:38 AM, Mansour Moufid <mansourmoufid at gmail.com> wrote:
> 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.

Yes... that happens because "9223372036854775808L" doesn't fit into a
signed long; "-9223372036854775808L" does, but the standard states
that we aren't allowed to take that into account when we parse integer

The output happens to be the same for your testcase because
9223372036854775808UL happens to be the value you want, and it gets
implicitly converted to a signed integer; it is possible to write
testcases which would be affected by the difference.


More information about the cfe-dev mailing list