tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] RE :Re: add warning for signed unsigned comparisions


From: Christian JULLIEN
Subject: [Tinycc-devel] RE :Re: add warning for signed unsigned comparisions
Date: Fri, 10 Jan 2014 10:58:39 +0100 (CET)

Remember that the signess of char is implementation, more especially machine, dependant.

The correct way to insure num_signed is signed is to declare

  signed char num_signed = 128;
  unsigned char num_unsigned = 128;

On a machine where a char is unsigned, the compiler has no reasons to protest unless it use something like warn-portability. Generally, most compilers have a flag like char=signed for force signess

Christian

----- Message d'origine -----
De : "Romain ..." <address@hidden>
Date ven. 10/01/2014 10:48 (GMT +01:00)
À : "address@hidden" <address@hidden>
Objet : Re: [Tinycc-devel] add warning for signed unsigned comparisions

Hi Carlos

It would be interresting to test wether the same bug happens with lower numbers. Because I found two different reasons for this behaviours : either there's a problem with assigning 128 to a signed char (which is supposed to be bound to -128 +127) or it is caussed by an implicit cast during the comparison.

It's strange because gcc haven't this behaviour.

regards,
Romain

On Jan 6, 2014 4:58 PM, "Carlos Montiers" <address@hidden> wrote:
Hello. Please can add support for tiny c warning signed comparisions with unsigned comparisions.
 
For warning code like this:
 
#include <stdio.h>
int main()
{
  char num_signed = 128;
  unsigned char num_unsigned = 128;
  if (num_signed == num_unsigned) {
    printf("Equals\n");
  } else {
    printf("Not Equals\n");
  }
  return 0;
}
 
 

_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel




_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]