3 ms·
I'm not a professional programmer by any stretch, but wouldn't this problem completely go away if the C and C++ compilers detect a single = inside an if stateme
by sigkill 13y ago
I'm not a professional programmer by any stretch, but wouldn't this problem completely go away if the C and C++ compilers detect a single = inside an if statement and outright refuse it. Either that or automatically substitute the assignment with checking for instances inside the if-condition.
The reason I'm asking is, because I don't know if there's ever a case where you'd want to assign right inside the if-condition. Is there?
- comex 13y agoThere can be: if (Foo *foo = getFoo()) { // getFoo returns null if there is no foo // There is a foo } However, this problem is basically entirely addressed by compiler warnings, which generally ask you to add an extra set of parens for this case.