This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/23068] New: errors in comparison operator < for char


The < operator returns 1 for comparison of char (or unsigned char)
when it should return 0.  The <= operator does not show this bug.

gcc-4.1 snapshots 20050604 and latest 20050723 compiled and
used on i686-pc-linux (Suse 8.1)

Here is a (very small) test source.
**************************************************
#include <stdio.h>
int main(void){
  unsigned char c;
  for (c=127;c<130;c++){
  printf("test : (char) %d <= 128 result %d\n",c,c<=128);
  printf("test : (char) %d < 128 result %d\n",c,c<128);
  }
  return 0;
}
****************************************************
Output:
jp@brea:~/agreg/src/c> ./comparchar
test : (char) 127 <= 128 result 1
test : (char) 127 < 128 result 1
test : (char) 128 <= 128 result 1
test : (char) 128 < 128 result 1             BUG
test : (char) 129 <= 128 result 0
test : (char) 129 < 128 result 1             BUG

Here, the loop is, curiously, correct even if the test is not.
On my original source (much too long for inclusion), the loop
fails (infinite loop) since, because of the bug, the end-test is never satisfied.

As a reference, here is the (correct) output of the same source,
compiled on the same machine with gcc-3.6
test : (char) 127 <= 128 result 1
test : (char) 127 < 128 result 1
test : (char) 128 <= 128 result 1
test : (char) 128 < 128 result 0
test : (char) 129 <= 128 result 0
test : (char) 129 < 128 result 0

-- 
           Summary: errors in comparison operator < for char
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Jean-pierre dot vial at wanadoo dot fr
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23068


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]