I was reviewing some code that a friend of mine wrote and was wondering what exactly this declaration did...
(This is only a snippet)
I have never seen this before.Code:bool x; bool y; x = y !=0;
I was reviewing some code that a friend of mine wrote and was wondering what exactly this declaration did...
(This is only a snippet)
I have never seen this before.Code:bool x; bool y; x = y !=0;
Let us assume that y has been initialised. What is the result of (y != 0)? Observe that it is assigned to x.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Hah so obvious, thank you...
It should give you a warning about comparing bool to int, but it should be the same as: x = y;
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Out of curiosity, but which compiler emits such a warning here?Originally Posted by cpjust
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
bool != int
That's not merely a boolean comparison, at least not as far as more strongly typed languages such as pascal are concerned.
I would expect (or at least hope for) a warning as it may be that y was meant to be declared as an int.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
I'm pretty sure Visual C++ has that warning (at Warning Level 4). I don't have a VC++ to try it on right now though.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010