A simple one...
-
Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad
I would wonder whether or not it was originally something like:
if (x == **FALSE**) { y = 0; } else { y = x; }
(With FALSE being 0 of course.)
-
I would wonder whether or not it was originally something like:
if (x == **FALSE**) { y = 0; } else { y = x; }
(With FALSE being 0 of course.)
Something similar: if (x == false) { return false; } else { return true; }
Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio
-
Something similar: if (x == false) { return false; } else { return true; }
Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio
Your example is from someone not knowing (or being reluctant to use) boolean logic:
return (x != false);
would have been the same.
Failure is not an option - it's built right in.
-
Your example is from someone not knowing (or being reluctant to use) boolean logic:
return (x != false);
would have been the same.
Failure is not an option - it's built right in.
Or just: return x;
Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio
-
I would wonder whether or not it was originally something like:
if (x == **FALSE**) { y = 0; } else { y = x; }
(With FALSE being 0 of course.)
PIEBALDconsult wrote:
(With FALSE being 0 of course.)
No longer. C# is getting stricter. You have to explicitly do a type cast to escape the compiler wrath and whip.
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Or just: return x;
Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio
Sure. That would convert X's type (maybe BOOL?) implicitly to bool, whereas the operator!= I used does this explicitly. It probably doesn't matter.
Failure is not an option - it's built right in.
-
Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad
-
Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad
Good :) Great :laugh: High level of thinking :laugh::laugh::laugh:
Regards, Sylvester G
-
Does it make more sense if
x
is of typesigned int
andy
of typeunsigned int
?http://www.readytogiveup.com/[^] - Do something special today.