News for hackers. Stuff that matters.
Re:Named Booleans prevent C++ bugs and save you time by IshKebab on Saturday February 18, 2023 @07:50AM (#34846526)
That depends. In some cases the compiler will be able to determine that `expensiveCheck()` has no side effects and make them equivalent. But you can't really rely on it.

And in any case the author misidentified the problem and solution. The problem is that C++ coerces bool to int. I'm 99% sure there's a warning for that that you can turn into an error.

Re:Named Booleans prevent C++ bugs and save you time by kqr on Saturday February 18, 2023 @01:03PM (#34849249)
Ah, the mythical sufficiently smart compiler! http://wiki.c2.com/?SufficientlySmartCompiler
Re:Named Booleans prevent C++ bugs and save you time by IshKebab on Saturday February 18, 2023 @05:32PM (#34851784)
That's a different thing - the "sufficiently smart compiler" is postulating that it doesn't matter if a language is not very high performance because somehow magically there will one day be a compiler that can just figure out how to optimise the code in every case.

I'm just saying that in this particular case, sometimes the compiler will be able to optimise it but you can't rely on it.

https://godbolt.org/z/WshcfWPEh