简体   繁体   中英

C strange shifting behaviour

The following line:

printf("%ld\n", ((long) 7 << 63) >> 63));

Outputs -1

I've checked and

sizeof(long) == 8

Why is this happening?

((long) 7 << 63) >> 63)

调用未定义的行为,因为(long) 7 << 63long无法表示。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM