|
-
August 30th, 2002, 11:28 PM
#1
A question about #define
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
-
August 30th, 2002, 11:36 PM
#2
Sometimes you want a macro such as ASSERT to amount to nothing in specific builds, so you write code like this:
Code:
#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
Ce n'est que pour vous dire ce que je vous dis.
-
August 31st, 2002, 02:23 AM
#3
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.
Succinct is verbose for terse
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|