1

I am porting some C++ codebase from Windows VC10 to Mac XCode 10.7 .I have a macro which wraps the "assert()" .The Microsoft compiler has no problem with the following definition:

void assert(bool result, const char *call, const char *file, int line);
/// Wraps \c assert().//
#define MY_ASSERT(call) (mynsp::assert((call), #call, __FILE__, __LINE__))

while XCode throws me an error : Too many arguments provided to function-like macro invocation

Being complete noob to OS X and LLVM my question is how to work around this issue?

Btw, assert() declaration is wrapped with custom namespace (mynsp)

4

2 回答 2

2

The standard header <cassert> (or <assert.h> in C) defines assert as a macro, making that name unusable for any other purpose. Even if you don't include that header yourself, it's possible that it's included indirectly from some other header. That is probably why you only see the problem on one platform, not both.

The best option is to rename your function to avoid the clash; alternatively, you could use #undef assert in any file that wants to use the name for your purpose.

于 2013-09-03T11:40:19.610 回答
1

Right-click on assert in your prototype and choose "Jump to Definition". You'll see that it's #define'd somewhere, causing this problem for you.

You could #undef assert to get past it.

于 2013-09-03T11:38:00.383 回答