gcc(v4.1.2 cross-compiler) integer promotion problem
This is the test code.
char ch = 0xff;
int i = ch;
printf("%d\n", i);
In i386 gcc-4.4.5, the output is -1. But in powerpc-e300c3-linux-gnu-gcc-4.1.2(MPC8315 cross-compiler), the output is 255.
What is wrong? Why gcc-4.1.2 output is 255?
Thank开发者_开发问答s for your answer...
It is implementation-defined whether char
is signed or unsigned.
Apparently it is signed on your x86 compiler and unsigned on your PowerPC compiler.
For portability, use unsigned char
or signed char
wherever you care about the signedness.
精彩评论