1

I want to pass variable arguments to makecontext function as follows.

void a(...)
{ 
 ....
 makecontext( &stack, &func, ?, ? );
 ....
}

In the third parameter (?), I should have the number of variable arguments, while in the next ?, I should have all the arguments. How can this be done?

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356

1 Answers1

3

There's no way a variadic function can know the number of parameters it got. This information is not passed to it in any way.
The only way is by convention, which the caller will need to respect.
Two common conventions:
1. One of the first parameters would be the number of parameters.
2. All parameters are pointers, the last one must be NULL.

Note that printf also doesn't know what was passed to it. It just counts percent signs in the format string, and assumes it got a matching number of parameters.

ugoren
  • 16,023
  • 3
  • 35
  • 65