How do I add a pointer to an existing va_list?
I have a va_list which has one entry. The entry is an integer "hostObject". I need to add a second one to this va_list, which will be a pointer to another function that I plan to call at a later point in time. Sample code looks like this:
va_list adjustVarArgs( tag_t hostObject, ... )
{
va_list adjustedArgs;
// TODO: Somehow make 'adjustedArgs' va_list to contain the hostObject and the function pointer.
return adjustedArgs;
}
int Cfg0VariantConfigSavePost( METHOD_message_t * msg, va_list args )
{
va_list largs;
va_copy( largs, args );
tag_t hostObject = va_arg( largs, tag_t );
va_end( largs );
va_list adjustedArgs = adjustVarArgs( hostObject );
return Fnd0VariantConfigSavePost( msg, adjustedArgs );
return ITK_ok;
}
deleteExprObjects is the method I'm interested in. In general, I need to store 1. hostObject 2. function pointer: deleteExprsCallBack.
Please let me know how this can be done.
Thank you, Pavan.
source to share
According to the C standard (7.16), the complete list of available macros working on va_list
is:
Ad type -
va_list
which is a complete object type, suitable for storing information necessary for the macrova_start
,va_arg
,va_end
andva_copy
.
None of these 4 can add an item to va_list
, so this is not possible.
But since this is C ++, if you are using C ++ 11, you can take a package of variadic arguments and redirect it along with a function pointer:
template <typename... Args>
int Cfg0VariantConfigSavePost( METHOD_message_t * msg, tag_t hostObject, Args&&... args)
{
return Fnd0VariantConfigSavePost(msg,
some_func_ptr,
hostObject,
std::forward<Args>(args)...);
}
source to share