Pcc bites it (was Re: programming puzzle (silly))

Dave Decot decot at hpisod2.HP.COM
Wed Mar 15 06:34:26 AEST 1989


> Interesting -- the program *is* incorrect, because && has higher
> precedence than *= so it is parsed as:
> 
> 	(n&&m) *= n--
> 
> which is illegal because (n&&m) is not an lvalue.

No it isn't.  It doesn't have two different valid interpretations, so it's
not ambiguous, so the precedence rules are not applicable.  The only valid
parsing of the expression is

    n && (m *= n--).

> Our MetaWare and Green Hills compilers catch it, but every pcc-based
> compiler I tried compiled it with no warnings.

Your compilers are broken.

> Looking at the assembly-language generated, it appears that it compiled as:
> 
> 	n && (m*=n--)

...which is correct.

> What do other compilers out there do?

I hope they perform as above.  I'm tired of compiler bugs.

Dave



More information about the Comp.lang.c mailing list