Knowing the size of a Variable argument list
Is there a way to know the size of a variable argument list, without using a sentinel parameter.
For example, I have a function as below: -
void AssignArray(double* array, double first, ...);
and I used it as follows : -
AssignArray(array, 5.0, 6.0, 7.0);
Is there a way to determine that 3 parameters were passed to the function?
Re: Knowing the size of a Variable argument list
Quote:
Originally posted by Hamid Mushtaq
Is there a way to determine that 3 parameters were passed to the function?
Without any information, no. The number of arguments that are passed in a variable argument list is determined by either a sentinel value, or some other parameter that indicates the number of values, or some other value in your code that you've generated.
For example, you can do this:
Code:
void AssignArray(double* array, int numitems, double first, ...);
where "numitems" is the number of doubles in the variable argument list. Note that functions such as printf() use a format string to determine the number and type of the arguments. So you have a few options, but one option you don't have is a way to know the number of arguments without explicit information in your code somewhere.
Regards,
Paul McKenzie