Sign in to follow this  
ysg

Magical if-statement

Recommended Posts

ysg    192

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
ysg    192

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
Adaline    710

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
ysg    192

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this