[cfe-dev] warnings about large negative integer values

Mansour Moufid mansourmoufid at gmail.com
Wed Feb 1 07:38:48 PST 2012


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



More information about the cfe-dev mailing list