Click to See Complete Forum and Search --> : A question about #define
George Ma
August 30th, 2002, 11:28 PM
Hi, everyone!
Please look at the following statement,
--------
#define assert(x) ((void)0)
--------
What does the statement mean? What is the function
of "((void)0)" here?
Another question, there is a paramater "x" in the former
"assert(x)", why there is not a parameter in the latter
"((void)0)"?
Cheers,
George
Alexey B
August 30th, 2002, 11:36 PM
Sometimes you want a macro such as ASSERT to amount to nothing in specific builds, so you write code like this:#ifdef _DEBUG
#define CHECK(f, message) \
if (!(f)) \
{ \
int ID = AfxMessageBox(__FILE__ ":\n" _T(message), MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3); \
if (ID == IDABORT) \
exit(0); \
else if (ID == IDRETRY) \
AfxDebugBreak(); \
}
#else // _DEBUG
#define CHECK(f, message) ((void)0)
#endif// _DEBUG
cup
August 31st, 2002, 02:23 AM
What does the statement mean? What is the function
of "((void)0)" here?
It means do nothing. The alternative is
#define assert(x)
This may confuse some people but it defines assert(x) as nothing.
Another question, there is a paramater "x" in the former
"assert(x)", why there is not a parameter in the latter
"((void)0)"?
x is not used but is put in place to keep the compiler happy. assert(x) is normally used in to check whether x is non zero. If it is zero, the program will stop. This macro nullifies the effect of assert.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.