Re:Which one will execute faster, if(flag==0) or if(0==flag)?
by rcfox on Friday January 07, 2011 @11:34PM
(#2082219)
What about while? while(flag = 0) looks like a similar error, but while(foo = read()) is a common idiom.
[ Parent
| on HN ]
Re:Which one will execute faster, if(flag==0) or if(0==flag)?
by brownleej on Friday January 07, 2011 @11:40PM
(#2082236)
I think some compilers give a warning on while(foo = read()) but not on while((foo = read())).
Re:Which one will execute faster, if(flag==0) or if(0==flag)?
by CamperBob on Saturday January 08, 2011 @12:17AM
(#2082335)
That would be a broken compiler.
Re:Which one will execute faster, if(flag==0) or if(0==flag)?
by tbrownaw on Saturday January 08, 2011 @12:24AM
(#2082350)
No, I'm pretty sure that's intentional specifically to permit that idiom.
Re:Which one will execute faster, if(flag==0) or if(0==flag)?
by __david__ on Saturday January 08, 2011 @03:01AM
(#2082614)
It's usually a warning that you have to turn on explicitly, or one that you can at least turn off (thank heavens).
Re:Which one will execute faster, if(flag==0) or if(0==flag)?
by CamperBob on Saturday January 08, 2011 @12:17AM
(#2082334)
It's not the choice of keyword that (should) trigger the warning. It's the simple fact that an expression that evaluates to boolean contains an '='. This potential error is trivial for any compiler to flag.