Sign in to follow this  

Compiling without enabling Exceptions?

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I believe i have come across some tips before which stated that compiling your code without exception handling enabled can increase performance. Now since i do not use exception handling in my code, i tried it. But i use STL heavily and i suppose STL relies on exception handling which causes the warnings like e:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(574): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc So, 2 things i need to clear up. 1) Is it alright to disable exceptions when compiling my code even though i use STL, and if it is, how do i disable the warnings? Is there something i can define to tell STL to not use exception handling? 2) How do i disable exception handling? I dont know if my method is correct, all i did was disable C++ Exceptions under Code Generation in the Project Settings.

Share this post


Link to post
Share on other sites
I assume you have been able to get your code to compile already

so tell us, does it run faster?

can you prove that it does?

... well anyway, warnings can be disabled with #pragma statments, and probably also with command line switches. [I don't know the switches for the microsoft compilier though

in msvc:
# pragma warning(disable:4355) /* disable warning 4355 */

Share this post


Link to post
Share on other sites
In general, no, if a 3rd party code lib you're using throws exceptions, you can't turn it off in code that uses them. In general, I'd say that the overhead of exceptions is negligible until an exception is thrown. The framework for them takes up a little more space on the stack, but I'm pretty sure that's it.

If you really want to disable exceptions for your tighter loops, you can. In VS, The main problem is that you can't pragma it. It's on a per .cpp file basis. Put the code for your tight loop in a .cpp. You can disable exceptions for that file by right clicking it in your solution explorer, hitting Properties, and setting ConfigurationProperties->C/C++->Code Generation->Enable C++ Exceptions to no.

Let me know if it runs any faster.

Also, as an aside, disabling a warning for something like 4530 is a Very Bad Thing. Never, ever just disable warnings unless you know what happens if you do. In this case, an exception -can- still be thrown. If one is, all hell will break loose, and it will do so intermittently, lol.

Share this post


Link to post
Share on other sites
Good news and bad news.

Good news: According to the guys who wrote the default STL implementation shipped with MSVC, you can disable exception code generated in the standard library if you #define _HAS_EXCEPTIONS to be 0.

Bad news: There's a bad interaction with other pre-processor macros, like _STATIC_CPPLIB that may cause _HAS_EXCEPTIONS 0 to not work.

Share this post


Link to post
Share on other sites
Well currently im not doing much, just drawing 1 low poly mesh onscreen. So there is no visible difference. I'll look into it when my application has grown much bigger.

Share this post


Link to post
Share on other sites

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this