I have this function:
void print(THashEntry *entry, ...)
{
va_list parameters;
va_start(parameters, entry);
while (true)
{
THashEntry *currentEntry = va_arg(parameters, THashEntry *);
if (!currentEntry)
{
break;
}
printf("%s\n", currentEntry->value);
}
va_end(parameters);
}
I pass adresses of these entries into the function and then I want to access their member "value" and print it.
However when I try to obtain a parameter via va_arg, it returns me not the first, but the second parameter right from the start and when another loop of cycle goes in, it's segmentation fault.
va_argwill not returnentry, but the first argument afterentry. That's how it works. Printentry->valuebefore you enter the loop.printfandscanffamilies of functions manage it by scanning the format string and finding the conversion specifiers leaving it up to the programer to insure that the number of conversion specifiers does not exceed the number of supplied varidac arguments.