Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是测试代码。
char ch = 0xff; int i = ch; printf("%d\n", i);
在 i386 gcc-4.4.5 中,输出为 -1。但在 powerpc-e300c3-linux-gnu-gcc-4.1.2(MPC8315 交叉编译器)中,输出为 255。
怎么了?为什么 gcc-4.1.2 的输出是 255?
感谢您的回答...
char是有符号还是无符号 是实现定义的。
char
显然,它在您的 x86 编译器上已签名,而在您的 PowerPC 编译器上未签名。
为了便携性,使用unsigned char或signed char您关心签名的任何地方。
unsigned char
signed char