Link to home
Start Free TrialLog in
Avatar of mjgaudette
mjgaudette

asked on

use of va_arg

Can anyone explain how va_arg works and give an example?
ASKER CERTIFIED SOLUTION
Avatar of rmichels
rmichels

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mjgaudette
mjgaudette

ASKER

So assuming the variables are all passed on the stack, va_start returns the address of the first argument and va_arg moves backwards through the list until it gets to the last argument?
yes that is correct, you tell va_start the last fixed parameter(before the optional parameters start).  You then tell va_arg the type of variable to get, so it knows the size on the stack.  I do not use these macros much, but they do come in handy.