开发者

Variadic Macros : how to solve "too many actual parameters for macro.."

开发者 https://www.devze.com 2022-12-21 08:01 出处:网络
Ive been working on getting some of my code originally built on the mac to run under Visual Studio 2008 Express and have run into a weird problem with the variadic macros i use for my assert code :

Ive been working on getting some of my code originally built on the mac to run under Visual Studio 2008 Express and have run into a weird problem with the variadic macros i use for my assert code :

The macro is defined as :

#define SH_ASSERT( assertID, exp, description,开发者_StackOverflow中文版 ... ) shAssertBasic( int(exp), assertID, description, __LINE__, __FILE__ , ##__VA_ARGS__ ) 

This all works fine under gcc (under osx) and used to run under VS 2005 however with 2008 I get the following warning :

 warning C4002: too many actual parameters for macro 'SH_ASSERT'

The calling code is simply :

SH_ASSERT(0, donkeys != aliens , "Donkeys are Aliens Code : Code %d condition %d" , 55, 666);

I'm sure Im missing something simple and my google foo is failing me...

Thanks.


Change the argument order (put description with the ... part) to do something like this:

#define SH_ASSERT( assertID, exp, ... ) shAssertBasic( int(exp), assertID, __LINE__, __FILE__, __VA_ARGS__ )

It should do the trick, You also have the possibility to suppress the warning in windows:

#pragma warning (push)
#pragma warning( disable:code/number )
#pragma warning (pop)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号