-
|
How is your FormatString() function able to to take in variable arguments? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This is using a special system in C called variadic arguments. You can see it in the code here where the FormatString(umw DestSize, char* Dest, char* Format, ...)that In order to handle those variadic arguments, C macros are used that come from
So, you can see how this is used in the code of the function: va_start(ArgList, Format);
umw Result = FormatStringList(DestSize, Dest, Format, ArgList);
va_end(ArgList);That ellipsis ( |
Beta Was this translation helpful? Give feedback.
This is using a special system in C called variadic arguments. You can see it in the code here where the
...invokes it.that
...means this function may take more arguments and at compile time, we do not know how many or what type these argument(s) are AOT (ahead of time).In order to handle those variadic arguments, C macros are used that come from
<stdarg,h>.Those macros are:
va_list: a special type that represents the list of the extra arguments that are passed in.va_start: this initializesva_list-- specifically clarifying where it begins.va_arg: this pulls out the next argument and its type from the list.va_end: this cl…