News for hackers. Stuff that matters.
Re:Orthodox C++ by asddubs on Sunday December 27, 2020 @06:53PM (#25555266)
I don't agree with the article but this is actually true, exceptions and RTTI are the two exceptions to the zero overhead principle. if you don't use -fno-exceptions (or mark the function as noexcept), every function will generate additional instructions to deal with potential exceptions happening

https://en.cppreference.com/w/cpp/language/Zero-overhead_pri...

Re:Orthodox C++ by junon on Monday December 28, 2020 @12:27AM (#25556948)
This is false. Most code emitted by modern compilers incurs no overhead for exceptions except for when they are actually thrown. This is a historical rule that is no longer true.

https://stackoverflow.com/a/13836329/510036

Re:Orthodox C++ by gmueckl on Tuesday December 29, 2020 @01:27AM (#25567317)
There are instances where I can get current GCC to generate less instructions as part of the normal control flow when adding noexcept declarations. This is quite surprising given the common claim that exceptions shouldn't affect that. Unfortunately, I think I lost the example where I could reproduce it in the Compiler Explorer.
Re:Orthodox C++ by junon on Tuesday December 29, 2020 @02:46AM (#25567668)
How convenient
Re:Orthodox C++ by gmueckl on Tuesday December 29, 2020 @03:53AM (#25567980)
I reproduced it:

https://godbolt.org/z/nzof4s

test() with exceptions enabled is two instructions longer in the normal code path.

Re:Orthodox C++ by asddubs on Monday December 28, 2020 @03:25AM (#25557635)
I don't think it really contradicts what I said, I didn't say extra instructions were executed on each function call, just generated. I guess it depends on how you define overhead, but if you compile a program that does not use exceptions with exceptions on, it will run slower if you benchmark it. That being said, I do use exceptions and think they're obviously worth it, but there is an overhead to them, even if it's not as simple as "x additional instructions are executed"
Re:Orthodox C++ by nzmsv on Monday December 28, 2020 @10:19AM (#25559814)
That would be one strange benchmark then. It would have to be benchmarking something other than the code in question.

Simple analogy: let's say you have a program that has 10 functions in it. You write a benchmark that exercises one of these and never (no, not once, never) calls the other functions. The other 9 are truly dead code. Would you expect the benchmark result to be different between that and a program that only included the one function being benchmarked?

Re:Orthodox C++ by asddubs on Monday December 28, 2020 @10:35AM (#25559956)
yes if the generated code causes e.g. more cache misses and branch mispredictions, which additional instructions inbetween the executed ones will
Re:Orthodox C++ by junon on Tuesday December 29, 2020 @02:45AM (#25567666)
Did you benchmark with layout randomization?