Alex Rivera | Logout

What does "#define assert(exp) ((void) 0)" do?

Asked 2009-05-20T03:28:59.247
11

I came across this preprocessor definition while reading the source code in Windows Research Kernel (WRK) 1.2:

#define assert(exp) ((void) 0)

What does this code do? Why is it defined?

Edit
Report

1 Answer

8

To expand on what bdonlan says, the reason the macro does not expand empty is because if it did, then something like:

assert(something) // oops, missed the semi-colon
assert(another_thing);

would compile in release mode but not in debug mode. The reason it is ((void) 0) rather than just 0 is to prevent "statement with no effect" warnings (or whatever MSVC calls them).

answered 2009-05-20T11:44:43.157

Your Answer