• Advertisement
Sign in to follow this  

Magical if-statement

This topic is 1771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if (foo == foo || bar == bar) {
...
}
else {
...
}

This is an old one.  My software lead did this, I showed it to her and she said: Umm... I... yeah... I wasn't thinking :) .

 

We both laughed and I rewrote it all :) .

Share this post


Link to post
Share on other sites
Advertisement

If it's a floating point number with a NaN value then (foo != foo) and the code could go into the else block.

I'm 90% certain that it was an into of some sort.  It was pretty funny and

we both were like, yeah, this will not be mentioned in polite company

ever again :) .

Share this post


Link to post
Share on other sites

when x is a floating point number, if (x!=x) permits to check if x is NaN. This is terribly ugly .... but that's it wacko.png

Edited by Tournicoti

Share this post


Link to post
Share on other sites

Couldn't foo and bar also be declared volotile?
 

I don't think I've ever used volatile in my entire coding career.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement