--- Begin Message ---
Package: gcc-4.1
Version: 4.1.1-21
Severity: normal
Hi,
The following code produce different outputs on x86 platform and powerpc
platform:
~$ cat a.c
#include <stdio.h>
int main (void)
{
char ch [2] = { 127, 180 };
signed char sch [2] = { 127, 180 };
unsigned uch [2] = { 127, 180 };
printf ("char: %d %d\n", ch[0], ch[1]);
printf ("signed char: %d %d\n", sch[0], sch[1]);
printf ("unsigned char: %d %d\n", uch[0], uch[1]);
};
x86 or x64 platform, it outputs:
~$ ./a.out
char: 127 -76
signed char: 127 -76
unsigned char: 127 180
powerpc platform, it outputs:
~$ ./a.out
char: 127 180
signed char: 127 -76
unsigned char: 127 180
a.c is compiled by `gcc a.c`
I found this problem when checking the fcitx crash problem on ppc
platform. After a deep digging, I found the problem was caused by the
default signedness of char.
After adding `signed` to force the compiler use the singed char, fcitx
works well on ppc.
I found the fcitx crashing prolem on ppc more than 3 months ago. I
had no time to report it till today. So this problem has been there for
more than 3 months.
I'm not quite sure if the debian building system is using gcc-4.1. But
apprently this problem exists in the gcc which debian building system
is using.
There may be other packages affected by this problem.
Best Regards,
Bin Tian
-- System Information:
Debian Release: 4.0
APT prefers testing
APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-amd64
Locale: LANG=zh_CN, LC_CTYPE=zh_CN (charmap=GB2312)
Versions of packages gcc-4.1 depends on:
ii binutils 2.17-3 The GNU assembler, linker and bina
ii cpp-4.1 4.1.1-21 The GNU C preprocessor
ii gcc-4.1-base 4.1.1-21 The GNU Compiler Collection (base
ii libc6 2.3.6.ds1-10 GNU C Library: Shared libraries
ii libgcc1 1:4.1.1-21 GCC support library
ii libssp0 4.1.1-21 GCC stack smashing protection libr
Versions of packages gcc-4.1 recommends:
ii libc6-dev 2.3.6.ds1-10 GNU C Library: Development Librari
pn libmudflap0-dev <none> (no description available)
-- no debconf information
--- End Message ---
--- Begin Message ---
Bin Tian <tianbin@cernet.edu.cn> writes:
> The following code produce different outputs on x86 platform and powerpc
> platform:
>
> ~$ cat a.c
>
> #include <stdio.h>
> int main (void)
> {
> char ch [2] = { 127, 180 };
> signed char sch [2] = { 127, 180 };
> unsigned uch [2] = { 127, 180 };
>
> printf ("char: %d %d\n", ch[0], ch[1]);
> printf ("signed char: %d %d\n", sch[0], sch[1]);
> printf ("unsigned char: %d %d\n", uch[0], uch[1]);
> };
This is allowed by the C standard; the signedness of char is
implementation-defined. Moreover, we cannot change it, since that
would break the ABI. So this is not a bug.
--
Falk
--- End Message ---