Reputation: 3181
I have a va_list which has a single entry in it. The entry is an integer 'hostObject'. I need to add a second one to this va_list which is going to be a pointer to another function which I plan to invoke at a later point of time. The sample code is as below:
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 a method which I am interested in. On the whole, I need to store 1. hostObject 2. pointer to function: deleteExprsCallBack.
Please let me know how this can be done.
Thanks, Pavan.
Upvotes: 3
Views: 529
Reputation: 303537
According to the C Standard (7.16), the complete list of available macros operating on a va_list
is:
The type declared is
va_list
which is a complete object type suitable for holding information needed by the macrosva_start
,va_arg
,va_end
, andva_copy
.
None of those 4 can add an element to a va_list
so this is not possible.
But since this C++, if you're using C++11, you could take a variadic argument pack and forward it along with your function pointer attached:
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)...);
}
Upvotes: 1