[Bug c/29771] New: u != '\377' always true (u is unsigned char)

2006-11-08 Thread r dot c dot ladan at gmail dot com
Compiling this program using -Wall -Wcast-qual:

>>>>

#include 

int main(int argc, char *argv[]) {
unsigned char u;
u = '\377';
printf("u=%i\n", u); /* 255, as expected */
/*  if (u != '\0')*//* ok */
if (u != '\377')/* ERROR (?) : always true due to
limited range of data type */
printf("wow");
return(0);
}

<<<<

gives the warning "comparison is always true due to limited range of data type"

platform is i386/Pentium 4M running FreeBSD 6.2-BETA3

Note the operator !=

Also, the complementary comparison u != '\0' does *not* give a warning
"comparison is always false due to limited data type"


-- 
   Summary: u != '\377' always true (u is unsigned char)
   Product: gcc
   Version: 3.4.6
Status: UNCONFIRMED
  Severity: normal
      Priority: P3
     Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: r dot c dot ladan at gmail dot com
 GCC build triplet: i386-undermydesk-freebsd
  GCC host triplet: i386-undermydesk-freebsd
GCC target triplet: i386-undermydesk-freebsd


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



[Bug c/29771] u != '\377' always true (u is unsigned char)

2006-11-08 Thread r dot c dot ladan at gmail dot com


--- Comment #2 from r dot c dot ladan at gmail dot com  2006-11-08 23:52 
---
(In reply to comment #1)
> '\377' in C is of type int.
> 
Ok, the comparison works with (u != 0xff), thus without the quotes.


-- 


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