>>I'm not familiar with vs_list and va_start (though I can guess that 
>>vfprintf() is probably a variant of fprintf()), could you give a brief 
>>explanation?
>
>I semi-understand it -- enough to know what it does but I couldn't
>implement it without lots of thinking :)
>
>Basically, you can specify a variable number of arguments to functions,
>the compiler does some magic and this comes as a pointer to an array of
>char *'s.  Any function that does this must know how many arguments to
>process, this is where the format string in *printf come in, it parses
>the string for % characters and replaces them with the contents of the
>next argument in the list.  Needless to say, the type of the argument
>must match the type given in the format string.

No, there is no compiler magic just some C casting magic, you just need
to understand how arguments are passed to functions on the stack in C.

Essentially the va_start macro grabs the stack address after the last
specified argument into the va_list variable and subsequent uses of the
va_arg macro increment this pointer after use. That's is why if the wrong
type is given to va_arg it will get out of step with the stack frame.
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text

Reply via email to