Bug constant folding unsigned chars

Dave Gillespie daveg at near.cs.caltech.edu
Sun Jul 29 11:00:28 AEST 1990


On 27 Jul 90 20:15:17 GMT, hays at isc.intel.com (Kirk Hays) said:
> In article <9007250601.AA07615 at csvax.cs.caltech.edu> daveg at CSVAX.CS.CALTECH.EDU (David Gillespie) writes:
>>I tried the following program on gcc 1.37.1 under HP-UX 7.0.  I was
>>checking that IsUnsigned would be folded to a constant at compile-time.
>>It was, but in two cases the result was wrong!

[it worked for unsigned int, but not for unsigned short or unsigned char]

> Sorry, but the macro is K&R correct(sometimes), ANSI wrong, as the value
> conversion rules were open in K&R, but defined in ANSI.
> What you are seeing is ANSI compiler behavior.

[explanation of ANSI promotion rules]

> Frankly, I am surprised that Karl Heuer blew the macro; he is the walking
> lint, after all!

Karl's original message said the macro tested the *promoted* type of
the argument.  I just forgot the distinction, having grown up with
pre-ANSI compilers which used different promotion rules.  Sorry for
the confusion---Karl's track record is intact!

Now, whether I *agree* with ANSI's promotion rules is... well, let's
not start that again.

Can anybody see a way to define IsUnsigned that does check the true
type of the argument?

								-- Dave
--
Dave Gillespie
  256-80 Caltech Pasadena CA USA 91125
  daveg at csvax.cs.caltech.edu, ...!cit-vax!daveg



More information about the Comp.lang.c mailing list