zumalifeguard
zumalifeguard

Reputation: 9016

How can I tell if the Microsoft C++ code I'm running was compiled with the /EHa switch?

I need to make sure the header I'm using is compiled with the /EHa compiler switch?

How can I do that?

Upvotes: 0

Views: 75

Answers (1)

zumalifeguard
zumalifeguard

Reputation: 9016

inline bool CodeHasEHaSwitch()
{
    bool dtorCalled = false;

    struct CCheckEHaSwitch
    {
        CCheckEHaSwitch( bool& dtorCalled) : dtorCalled( dtorCalled ) {}
        ~CCheckEHaSwitch() {  dtorCalled = true; }
        bool& dtorCalled;

        static void Win32ExceptionTranslator( unsigned int nExceptionCode,
        EXCEPTION_POINTERS *pExceptionInfo )
        {  throw nExceptionCode; }
    };

    _se_translator_function pfnPrevSeTranslator =
        _set_se_translator( CCheckEHaSwitch::Win32ExceptionTranslator );
    try
    {
        CCheckEHaSwitch test( dtorCalled );

        *((int*)0) = 0;  // generate access violation
    }
    catch (unsigned int)
    {
    }

    _set_se_translator( pfnPrevSeTranslator );

    return dtorCalled;
}

Upvotes: 0

Related Questions