Subject: Re: archive.c/arm32
To: None <current-users@NetBSD.ORG>
From: Jaromir Dolecek <dolecek@ics.muni.cz>
List: current-users
Date: 03/24/1998 17:19:17
Todd Vierling wrote:
> [Quotes from multiple people]
> 
> : > In that case, I think that
> : > 	(int)val >= 0
> : > does the right thing in every useful case:
> 
> : However, the original goal was to come up with an expression which
> : yields the correct result _and_ which avoids the gcc "comparison is
> : always 1 due to limited range of data type" warning.
> 
> Better: fix gcc or to be able to disable a few -W options.  Then go and
> remove all similar workarounds from the entire code tree. 

The original code was really  bad (gcc _correctly_ complained about
"comparison ...."). Disabling warnings is a bit too short-term
"solution" ;)

> Short-circuit math is allowed to cause warnings like this in some cases (as
> a portability issue), but it should not be worked around when the
> short-circuit is intended.  That causes slower code at the expense of a
> so-called "clean compile."

The original code seem to work only with char which is signed by
default.  It would be definitely corrected - I see no reason why
should be gcc called brain damaged when it warn about this fact.

Shouldn't ((signed char)val >= 0) or ((unsigned char)var < 128) just do 
the same as original code has done ?

Am I missing something obvious ?

> 
> : > ((int)val >= 0) yields the correct result, but also causes that
> : > warning.
> : 
> : No, it fails in implementations that have sizeof(char) == sizeof(int).
> 
> Which is *not* an impossibility, y'know.
> 
> : > a-HA.  Granted, a compiler is entitled to emit as many spurious messages
> : > as it likes, but this seems too clever by half...
> : 
> : That's why I really don't like the religious requirement of -Wall in our
> : compilation.
> 
> You mean "-Wall -Werror"?...  As I said, fix gcc, don't borf your code
> because GCC is being dain bramaged. 
> 

Jaromir
-- 
Jaromir Dolecek <dolecek@ics.muni.cz>	http://www.ics.muni.cz/~dolecek/
-------------------------------------------------------------------------
It is better never to have been born.  But who among us has such luck?
One in a million, perhaps.