Skip to contentSkip to conversation

char type is unsigned with PPC gcc?

DISCUSSION Stephane Laroche 2 participants 4 messages Apr 19, 2000

lore
Share & tools
lore
#0 lore raw

I just finished debugging the ASH shell, which wasn't running properly on my 860, and found out that it assumes (correctly if you ask me) that the type 'char' is signed.

GCC 2.95.2 is configured to have chars unsigned by default on the PowerPC platforms. The x86 GCC configures char to be signed... (looking at gcc/config/rs6000/rs6000.h for the ppc)

Anyone knows why the PowerPC is different in this regard?

Surely I'm not the first one to come across this problem. Should I fix ASH or should I reconfigured gcc to default to signed char? I think the latter is a better idea since, if I remember correctly, ANSI C says that char should be signed.

-Stephane

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 4 lines · Stephane Laroche

I just finished debugging the ASH shell, which wasn't running properly on my 860, and found out that it assumes (correctly if you ask me) that the type 'char' is signed.

No, signed char lead to bugs, I've already been vocal enough about it so I won't repeat myself. I personnally consider that the only good char is the unsigned char (signed char also lead to code bloat on many architecture which have load byte with zero extension but not with sign extension).

Quoted 5 lines

GCC 2.95.2 is configured to have chars unsigned by default on the PowerPC platforms. The x86 GCC configures char to be signed... (looking at gcc/config/rs6000/rs6000.h for the ppc)

Anyone knows why the PowerPC is different in this regard?

Because it's an ABI/Platform issue, not a compiler issue. Correctly written programs should never assume that a char is signed or unsigned. Any program which depends on this is buggy. This said, there are so many programs that are buggy that gcc gives you the option with -fsigned-char and -funsigned-char.

Quoted 5 lines

Surely I'm not the first one to come across this problem. Should I fix ASH or should I reconfigured gcc to default to signed char? I think the latter is a better idea since, if I remember correctly, ANSI C says that char should be signed.

No, ANSI C leaves it to the implementation. Besides, did I already mention that signed char leads to bugs ?

Gabriel.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#2 lore raw

Ok, message understood. Thanks for the info.

For the record, ASH 0.2 must then be modified to run properly on the PowerPC:

Change line 428 of expand.c to "signed char name;"

-Stephane

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#3 lore raw
Quoted 5 lines · Stephane Laroche

Ok, message understood. Thanks for the info.

For the record, ASH 0.2 must then be modified to run properly on the PowerPC:

Change line 428 of expand.c to "signed char name;"

I don't have the source offhand, so without any context it's not very useful. It is actually possible that you are covering a bug with this change (given the typical case in which the problem shows, it's far from unlikely).

Gabriel

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/