Warning given a value of unsigned long long variable in C

后端 未结 1 1567
醉酒成梦
醉酒成梦 2021-01-27 11:20

I am using Linux x86_64 with gcc 5.2.1 and I am using a code to ascertain the maximum value for \"unsigned long long\" variable in C programming language.

In my machine,

1条回答
  •  鱼传尺愫
    2021-01-27 12:07

    Your code is correct and this is a bogus warning.

    To avoid the warning you could write:

    unsigned long long a = 18446744073709551615ull;
    

    The warning is (slightly) useful for some integer literals, but not this particular one, and the compiler is not trying very hard to limit the warning to cases where it is useful.

    NB. Make sure you're using -std=c99 or -gnu99 or later; before 1999 C did not officially have unsigned long long, and different compilers did weird things with large integer literals.

    0 讨论(0)
提交回复
热议问题