linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* ppc_8xx-gcc from eldk strange behaviour
@ 2007-08-28 18:56 DI BACCO ANTONIO - technolabs
  2007-08-28 19:01 ` Scott Wood
  2007-08-29  4:50 ` Ricardo Scop
  0 siblings, 2 replies; 5+ messages in thread
From: DI BACCO ANTONIO - technolabs @ 2007-08-28 18:56 UTC (permalink / raw)
  To: linuxppc-embedded

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

Consider the following C code snippet:

#include <stdio.h>

int main()
{
  char x = -4;
    
  if (x < 0)
    printf("x is negative\n");
  else
    printf("x is positive\n");  
}

If I compile it with host gcc, there is no warning and the message "x is negative" is printed.
If I compile it with ppc_8xx-gcc there is a warning "main.c:11: warning: comparison is always false due to limited range of data type" and the program prints message "x is positive". 
To correct the problem I have to put signed before char.

Bye,
Antonio.

[-- Attachment #2: Type: text/html, Size: 1127 bytes --]

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

* Re: ppc_8xx-gcc from eldk strange behaviour
  2007-08-28 18:56 ppc_8xx-gcc from eldk strange behaviour DI BACCO ANTONIO - technolabs
@ 2007-08-28 19:01 ` Scott Wood
  2007-08-29  9:28   ` DI BACCO ANTONIO - technolabs
  2007-08-29  4:50 ` Ricardo Scop
  1 sibling, 1 reply; 5+ messages in thread
From: Scott Wood @ 2007-08-28 19:01 UTC (permalink / raw)
  To: DI BACCO ANTONIO - technolabs; +Cc: linuxppc-embedded

On Tue, Aug 28, 2007 at 08:56:10PM +0200, DI BACCO ANTONIO - technolabs wrote:
> If I compile it with host gcc, there is no warning and the message "x is negative" is printed.
> If I compile it with ppc_8xx-gcc there is a warning "main.c:11: warning: comparison is always false due to limited range of data type" and the program prints message "x is positive". 
> To correct the problem I have to put signed before char.

C does not specify the signedness of char.  If you care, you need to
explicitly specify.

-Scott

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

* Re: ppc_8xx-gcc from eldk strange behaviour
  2007-08-28 18:56 ppc_8xx-gcc from eldk strange behaviour DI BACCO ANTONIO - technolabs
  2007-08-28 19:01 ` Scott Wood
@ 2007-08-29  4:50 ` Ricardo Scop
  1 sibling, 0 replies; 5+ messages in thread
From: Ricardo Scop @ 2007-08-29  4:50 UTC (permalink / raw)
  To: linuxppc-embedded; +Cc: DI BACCO ANTONIO - technolabs

Hi, Antonio

On Tuesday 28 August 2007 15:56, DI BACCO ANTONIO - technolabs wrote:
> Consider the following C code snippet:
[snip]
>   char x = -4;
[snip]
>
> If I compile it with host gcc, there is no warning and the message "x is
> negative" is printed. If I compile it with ppc_8xx-gcc there is a warning
> "main.c:11: warning: comparison is always false due to limited range of
> data type" and the program prints message "x is positive". To correct the
> problem I have to put signed before char.
>

You can also use the -fsigned-char compilation flag, in this case.

-- 
Ricardo Scop.

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

* RE: ppc_8xx-gcc from eldk strange behaviour
  2007-08-28 19:01 ` Scott Wood
@ 2007-08-29  9:28   ` DI BACCO ANTONIO - technolabs
  2007-08-29 23:28     ` Wolfgang Denk
  0 siblings, 1 reply; 5+ messages in thread
From: DI BACCO ANTONIO - technolabs @ 2007-08-29  9:28 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-embedded

> C does not specify the signedness of char.  If you care, you need to
> explicitly specify.

Sorry, I didn't know this. Anyway I would expect the same behaviour from
both host gcc and ppc_8xx-gcc. In this case host gcc is wrong.=20

Bye,
Antonio.

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

* Re: ppc_8xx-gcc from eldk strange behaviour
  2007-08-29  9:28   ` DI BACCO ANTONIO - technolabs
@ 2007-08-29 23:28     ` Wolfgang Denk
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Denk @ 2007-08-29 23:28 UTC (permalink / raw)
  To: DI BACCO ANTONIO - technolabs; +Cc: linuxppc-embedded

In message <F1F6EC0C8B75034F9E3A79FC85122E8EA185B5@aquib01a> you wrote:
> > C does not specify the signedness of char.  If you care, you need to
> > explicitly specify.
> 
> Sorry, I didn't know this. Anyway I would expect the same behaviour from
> both host gcc and ppc_8xx-gcc. In this case host gcc is wrong. 

No, it is not wrong.  The  behaviour  is  just  not  defined  by  the
standard,  so  the compiler is free to do what he likes. Some systems
default to singend chars,  others  to  unsigned.  Both  is  perfectly
legal.

It is code that makes any such assumptions which is broken.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Death, when unnecessary, is a tragic thing.
	-- Flint, "Requiem for Methuselah", stardate 5843.7

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

end of thread, other threads:[~2007-08-29 23:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-28 18:56 ppc_8xx-gcc from eldk strange behaviour DI BACCO ANTONIO - technolabs
2007-08-28 19:01 ` Scott Wood
2007-08-29  9:28   ` DI BACCO ANTONIO - technolabs
2007-08-29 23:28     ` Wolfgang Denk
2007-08-29  4:50 ` Ricardo Scop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).