Domanda

I have an average c++ background however i haven't developed anything with MFC, and i came across a Lib which i need to make portable and there are alot of calls for assert for example

void putValue(LPCTSTR lpszValue)
    {
        ASSERT(AfxIsValidString(lpszValue));
                .
                .
                .
        }

and in MSDN

The most typical use of the ASSERT macro is to identify program errors during development. The argument given to ASSERT should be chosen so that it holds true only if the program is operating as intended. The macro evaluates the ASSERT argument and, if the argument expression is false (0), alerts the user and halts program execution. No action is taken if the argument is true (nonzero).

if i were to port this to be compiled in GCC, is the right thing to do is putting the condition in an if statement and throw an exception id the condition was valid?

È stato utile?

Soluzione

I think you can simply:

#ifndef ASSERT
#include <cassert>
#define ASSERT assert
#endif
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top