Re:Orthodox C++
by microtherion on Sunday December 27, 2020 @07:29PM
(#25555503)
"you don't pay for it" doesn't mean that no code gets generated for exceptions in this case, but that no code gets executed unless an exception gets thrown, and your example does not disprove that.
[ Parent
| on HN ]
Re:Orthodox C++
by arcticbull on Sunday December 27, 2020 @07:46PM
(#25555630)
Generated code has a cost in terms of size, of course, and in terms of performance via the addition of branching, branch mis-prediction penalty and decreased cache locality. This function invocation will also of course flush the pipeline and harm inlining. On a hot path this could be non-trivial.
While true it's also fewer branches than manual error handling via return values.
So the only "fast" option is to just not handle errors at all. Which is a terrible recommendation, of course.
Re:Orthodox C++
by alisonkisk on Monday December 28, 2020 @08:09AM
(#25558922)
That not the point, though. The point is that the cost is invisible with exceptions. For example, there could perhaps be an alternate version of C++ where every function is required to declare whether it could throw an exception (and a very smart compiler proves where it's possible), or that -fno-except flag is inverted so you have to opt in to exceptions.