"It's far more readable and — as a bonus — compiler is likely to produce more efficient code."
I want to learn more about this, when or how do you know a compiler produced efficient code? Does anybody have any interesting links for reads on this?
I want to learn more about this, when or how do you know a compiler produced efficient code? Does anybody have any interesting links for reads on this?
In this case C++ exceptions are practically zero cost so I don't quite believe that the compiler will generate more efficient code unless it elides some of the C version based on context (Otherwise the if statements aren't free)
I sometimes listen to the CppCast Podcast and one of the Hosts, Jason Turner, likes to write code in modern C++ for some vintage computers. He tests code bits in Compiler Explorer for that. He also has a YouTube Channel where he does that [2]
int rc = fx ();
if (rc != 0)
handle_error ();
can be simply converted into ASM ; call fx() and copy to acc
JNZ handle_error
; rest of code
handle_error:
; code of handle_error()
whereas exceptions in C++ need to generate a lot more code than this