C ++ return value and exception

I read somewhere that modern Intel processors have low-level equipment for implementing exceptions, and most compilers use it to make an exception faster than returning results using variables.

It's true? are exceptions faster than variables in relation to state return / response to state? reading on the topic seems to contradict this.

thank

+5
source share
6 answers

I do not know where you are reading this, but this is certainly not true. No hardware constructor would make exceptional circumstances, which by definition are unusual, work faster than ordinary ones. Also keep in mind that C, which according to TIOBE is the most popular system language, does not even support exceptions. It seems extremely unlikely that processors are optimized to handle exceptions of one language, the implementation of which is not even standardized among compilers.

Even if some exceptions were faster, you still should not use them outside your goal so that you do not confuse all other programmers in the world.

+11
source

, " ". , , -, , , :

++.

, , , : Intel , gcc 2.95 , , . , . , gcc 2.95 , , ++ Intel.

+14

. , . - , .

++ , ++ , .

+4

, .

, . . , . , . 0, true, -1, ...

, , . , , , - .

, , CPU . , . , , , . , .

. , , , , , . . ​​ Intel Pentium 4; .

+2

, , . , . gdb "catch throw" , , .

0

, , , :

  • try. , throw . SO.
  • throw. SO.
  • Untie the stack to get from throwto catch, and load the error handling code (c catch) into the processor cache. You must ignore this cost because you must pay this cost if you use status codes, not exceptions.
0
source

All Articles