There is a function my_init(...) that uses a variable argument list. The length of this list is not known, but there is a maximum of 100 and the elements are always char-arrays (means plain C-strings).
That's how I try to decode them:
void my_init(...)
{
va_list vl;
int tagCnt,tagLen=100;
char *listTag,*listValue;
va_start(vl,tagLen);
for (tagCnt=0; tagCnt<50; tagCnt++)
{
listTag=va_arg(vl,char*);
if (listTag==0) break;
listValue=va_arg(vl,char*);
... // do some usefult things here
}
va_end(vl);
}
...and I call this function this way:
my_init("tag1","value1",
"tag2","value2",
0);
So there are always pairs and the end of a list is marked with a 0. Unfortunately my_init() fails, after calling va_start() vl contains some crap that has nothing to do with input parameters and the calls to va_arg() return invalid pointers. So what is wrong in my code?
The code given above is shortened a bit so may be it does not compile...
Thanks!
==================================================================================
EDIT:
I changed code and call this way:
void my_init(int dummy,...)
{
va_list vl;
int tagCnt,tagLen=100;
char *listTag,*listValue;
va_start(vl,dummy);
for (tagCnt=0; tagCnt<50; tagCnt++)
{
listTag=va_arg(vl,char*);
if (listTag==0) break;
listValue=va_arg(vl,char*);
... // do some usefult things here
}
va_end(vl);
}
my_init(0,
"tag1","value1",
"tag2","value2",
0);
Independent from the used header file I now get other crap in my vl, stdargs.h or varargs.h do not make a difference...