wrote:
>
> Hello all,
>
> I have a quick question regarding the use of va_arg() with multiple
> parameter definitions. If the parameters are of different types, how
> do I know what type it is when using va_arg() ????
>
> For example, if I was to write a function similar to the good old
> printf() which takes multiple parameters of different types (eg. int,
> char*, etc) how do I know whether the parameter I'm processing is an
> int or a char* ???
You must figure out the type of the argument before
using va_arg() to retrieve its value. printf() can do this
by inspecting the format string; for example,
printf ("%s = %d (%.2f%%)\n",
implies that the second through fourth arguments must be a
`char*', an `int', and a `double', respectively.
Note that the arguments corresponding to `...' are subject
to promotion. That is, if you pass a `float' value it will be
promoted to `double' and you must retrieve it as such. There
are a few unfortunate situations where the promotion rules are
implementation-defined -- for example, `unsigned short' might
promote to `int' or to `unsigned int' -- and in such cases you
can't write 100% portable code.
--