更新时间:2023-11-10 12:31:04
根据K&R 第 2 版 对于有符号值的右移,结果取决于实现.
According to K&R 2nd edition the results are implementation-dependent for right shifts of signed values.
Wikipedia 说 C/C++通常"对有符号值实现算术移位.
Wikipedia says that C/C++ 'usually' implements an arithmetic shift on signed values.
基本上你需要测试你的编译器或者不依赖它.我对当前 MS C++ 编译器的 VS2008 帮助说他们的编译器进行了算术移位.
Basically you need to either test your compiler or not rely on it. My VS2008 help for the current MS C++ compiler says that their compiler does an arithmetic shift.