LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* gcc version 2.95.3 20010315 (release/MontaVista) cross compiler
@ 2003-12-17 23:02 David C. Chiu
  2003-12-17 23:17 ` Guy Streeter
  2003-12-17 23:27 ` Bret Indrelee
  0 siblings, 2 replies; 3+ messages in thread
From: David C. Chiu @ 2003-12-17 23:02 UTC (permalink / raw)
  To: linuxppc-embedded


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" );
        else
                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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc version 2.95.3 20010315 (release/MontaVista) cross compiler
  2003-12-17 23:02 gcc version 2.95.3 20010315 (release/MontaVista) cross compiler David C. Chiu
@ 2003-12-17 23:17 ` Guy Streeter
  2003-12-17 23:27 ` Bret Indrelee
  1 sibling, 0 replies; 3+ messages in thread
From: Guy Streeter @ 2003-12-17 23:17 UTC (permalink / raw)
  To: David C. Chiu; +Cc: linuxppc-embedded


On Wed, 2003-12-17 at 17:02, David C. Chiu wrote:
> 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" );
>         else
>                 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 ;-)

This behavior is indeed "normal". For some reason (compatibility with
AIX, I think) the gcc compiler for ppc has always made char unsigned by
default.
Try adding the -fsigned-char option to you gcc command line.

--Guy


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc version 2.95.3 20010315 (release/MontaVista) cross compiler
  2003-12-17 23:02 gcc version 2.95.3 20010315 (release/MontaVista) cross compiler David C. Chiu
  2003-12-17 23:17 ` Guy Streeter
@ 2003-12-17 23:27 ` Bret Indrelee
  1 sibling, 0 replies; 3+ messages in thread
From: Bret Indrelee @ 2003-12-17 23:27 UTC (permalink / raw)
  To: David C. Chiu; +Cc: linuxppc-embedded


On Wed, 17 Dec 2003, David C. Chiu wrote:
>
> 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.

[ snip ]

> 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 ;-)

It is allowable by the specification. C89 allowed char to be either
signed or unsigned, it was up to the implementation to decide which.

-Bret

--
Bret Indrelee                 QLogic Corporation
Bret.Indrelee@qlogic.com      6321 Bury Drive, St 13, Eden Prairie, MN 55346


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-17 23:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-17 23:02 gcc version 2.95.3 20010315 (release/MontaVista) cross compiler David C. Chiu
2003-12-17 23:17 ` Guy Streeter
2003-12-17 23:27 ` Bret Indrelee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox