gcc version 2.95.3 20010315 (release/MontaVista) cross compiler

David C. Chiu dchiu at ariodata.com
Thu Dec 18 10:02:37 EST 2003

We're experiencing some unexpected behavior with binary generated with
the said version of gcc; namely that variables declared to char appear
to be defaulting to unsigned char.

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char** args, char** envs )
        char sc;
        unsigned char uc;

        sc = uc = -3;

        printf( "signed char: %d unsigned char: %d\n", sc, uc );
        if ( sc > (char)0 )
                printf( "sc is greater than zero\n" );
                printf( "sc is less or equal to zero\n" );

        return 0;

The preceeding code would produce the following unexpected result --

signed char: 253 unsigned char: 253
sc is greater than zero

Making the following change --

        signed char sc;
        unsigned char uc;

Would produce the expected result --

signed char: -3 unsigned char: 253
sc is less or equal to zero

Can someone shed some light on this? (As in, is this "normal" and we do
not know only because we've been living under a rock ;-)

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

More information about the Linuxppc-embedded mailing list