[PATCH] Warn about bogus conditional operators

Andi Kleen andi@firstfloor.org
Sat Jan 17 10:48:00 GMT 2009


On Sat, Jan 17, 2009 at 11:00:26AM +0100, Andreas Schwab wrote:
> Andi Kleen <andi@firstfloor.org> writes:
> 
> > On Sat, Jan 17, 2009 at 10:16:43AM +0100, Andreas Schwab wrote:
> >> Andi Kleen <andi@firstfloor.org> writes:
> >> 
> >> > +?: with omitted middle operand GNU extension. When the condition
> >> > +in the ?: operator is a computed boolean the omitted value will
> >> 
> >> What is the difference between a boolean and a computed boolean?
> >
> > On the computed one you assign the value to something:
> >
> > 	var = a > b
> >
> > on a ordinary one you just jump (or decide for ?:) 
> >
> > 	if (a > b) { ... } 
> >
> > e.g. the bug I had was
> >
> > 	x != NULL ?: otherval
> 
> Did you just explain that is not a "computed boolean"?  

You're right it doesn't fit my definition very well because it 
is both jumped on (no pun intended) and assigned ("computed") away.
In this case computing wins over the jump.

The problem I had is the implicit 1 returned in the true
case, which was a mistake in my case and doesn't seem like
a very useful way to use ? in any case.

I admit the terminology is something I made up.
Perhaps there's a better term for this in the standard?

-Andi
-- 
ak@linux.intel.com -- Speaking for myself only.



More information about the Gcc-patches mailing list