How to pass NULL to the va_list function parameter?

I want to pass NULL to the 4th parameter of the following function:

bool CCMenuItemToggle :: initWithTarget (target CCObject *, SEL_MenuHandler selector, CCMenuItem * element, va_list arguments );

like this:

CCMenuItemToggle::initWithTarget(this, menu_selector(GOSound::toggleButtonCallback), NULL, NULL);

This is normal when I create it in Xcode (clang3.1). But when I port the code to android ndk (g ++ 4.7), it will not compile:

no viable conversion from 'int' to 'va_list' (aka '__builtin_va_list')

How can I deal with this?

+6
source share
3 answers

I assume that your code will work if you just use an empty va_list instead of NULL.

 CCMenuItemToggle::initWithTarget( this, menu_selector(GOSound::toggleButtonCallback) , NULL, va_list() ); 

Edit: Perhaps this alternative solution works with both compilers.

 va_list empty_va_list; CCMenuItemToggle::initWithTarget( this, menu_selector(GOSound::toggleButtonCallback) , NULL, empty_va_list ); 
+10
source

I see that this question has been answered, but it is not standard. the following code will go through a runtime error in Visual Studios; however, it works fine with g ++.

  va_list empty_va_list; CCMenuItemToggle::initWithTarget( this, menu_selector(GOSound::toggleButtonCallback), NULL, empty_va_list ); 

A better solution would be to create a couple of helper functions that build an empty va_list.

 va_list CCMenuItemToggle::createEmptyVa_list() { return doCreateEmptyVa_list(0); } va_list CCMenuItemToggle::doCreateEmptyVa_list(int i,...) { va_list vl; va_start(vl,i); return vl; } 

make doCreateEmptyVa_list private, and then when you call the function call

 CCMenuItemToggle::initWithTarget( this, menu_selector(GOSound::toggleButtonCallback), NULL, CreateEmptyVa_list() ); 
0
source

You cannot pass NULL as the fourth argument to your function. This function requires the va_list argument. NULL is generally not a valid initializer for a va_list object. So the answer to your question is: this is not possible.

How you should deal with this depends on what you are trying to do.

0
source

All Articles