为什么 - (长)(1UL <&lt; 63)==(长)(1UL <&lt; 63)?

时间:2014-09-02 08:38:40

标签: c

我有一个程序,我希望它可以这样:

original value as unsigned long: 9223372036854775808
converted to long: -9223372036854775808
converted to long then negative: 9223372036854775808

但它放了那些

original value as unsigned long: 9223372036854775808
converted to long: -9223372036854775808
converted to long then negative: -9223372036854775808

为什么 - (长)(1UL <&lt; 63)==(长)(1UL&lt;&lt; 63)这里?

    #include <stdio.h>
    int main() 
    {
        unsigned long i = 1UL << 63; 

        printf("original value as unsigned long: %lu\n", i); 

        printf("converted to long: %ld\n", (long)i);
        printf("converted to long then negtive: %ld\n", -(long)i);

        return 0;
    }

0 个答案:

没有答案