Advanced ASSERT macro

Started by
12 comments, last by Floating 20 years, 10 months ago
Enclosing it with {}?

I would have a similar problem:

if (functionA())  NEW_ASSERT(functionB());else  functionC();

would become:
if (functionA())  {    if (functionB())    {...}  };else  functionC();


Advertisement
Hmmm...
#define NEW_ASSERT(thing) \    if(thing) \        ; \    else \        if (AfxMessageBox("NEW_ASSERT error: " #thing "... ignore?",MB_YESNO|MB_ICONSTOP|MB_APPLMODAL)==IDNO) \            exit(0); \        else \            VERIFY(false);
Most correct way to fix the if 'problem' (and most likely the way its done in the official ASSERT macro):
void AssertFunc(char *file, int line, char *expr, bool a);#define ASSERT(X) AssertFunc(__FILE__,__LINE__, #X, X)void AssertFunc(char *file, int line, char *expr, bool a){     if(!a)     {          //  .          //  .          //  .     }}  


[edited by - Extrarius on June 5, 2003 12:52:13 AM]
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
if (functionA())
NEW_ASSERT(functionB());
else
functionC();


I hope you realize that this use of ASSERT is about as wrong as it gets ? You call functionB() in debug mode, but omit the call in release. What you probably want to do is check the return value in debug mode and don''t check it in release...

This topic is closed to new replies.

Advertisement