On Jun 21, 2010, at 10:22 AM, Bruce Evans wrote: > On Sun, 20 Jun 2010, Marcel Moolenaar wrote: > >> Log: >> Unbreak platforms with char unsigned by default. Oddly enough, GCC isn't >> satisfied with a simple cast to int in the check against EOF, so the fix >> is a bit involved by actually having to go through a temporary variable. > > Perhaps that is because gcc can see that the cast has no effect, so the > comparison can never be true if `c' is an unsigned char (unless unsigned > char has the same number of bits as signed int), but it cannot see that > the conversion to the temporary variable has the same null effect.
Very likely. However, by casting from char to int we do tell the compiler that this not grounds for a warning and as such we expect the compiler to treat this as any other scenario in which the compiler can infer that a condition is always true or false and as such optimize correctly. In other words: the compiler is correct in warning that (u_char != -1) is possibly not what the programmer wants, but I do expect that if we change the condition to (int != -1) by using a cast that the compiler will simply shut up and eliminate the if statement if it knows that the int will never be -1. > This remains broken, especially on platforms with chars unsigned. I can't make that claim. The expansion of the macro in the failing case may actually not have a problem by virtue of it working on an array of unsigned char. For all I know, EOF is never encountered and the check is simply not applicable. FYI, -- Marcel Moolenaar xcl...@mac.com _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"