cgccvariadic-functionsgcc4.8

Compile error with GCC when using variable arguments


I have a function that works with variable arguments and looks like this:

static int getIntValue(const int min,const int max,va_list *vl)
{
   int   listValue;

   listValue=va_arg(*vl,int);
   if (listValue<min) listValue=min;
   else if (listValue>max) listValue=max;
   return listValue;
}


unsigned long init_if_list(int *var,va_list vl)
{
   char *listTag;

   listTag=va_arg(vl,char*);
   if (!strcmp(listTag,INIT_SHOWUI)) initValues.uiFlags=getIntValue(INT_MIN,INT_MAX,&vl);

This code compiles well with Windows/VisualStudio 2012 and "older" GCC versions (like 4.7 on CentOS 6). But it fails when I try to compile it with GCC 4.8.4 / Ubuntu. Here I get following error:

error: cannot convert '__va_list_tag**' to '__va_list_tag (*)[1]' for argument '3' to 'int getIntValue(int, int, __va_list_tag (*)[1])'
   if (!strcmp(listTag,INIT_SHOWUI))                initValues.uiFlags=getIntValue(INT_MIN,INT_MAX,&vl);

Anybody an idea what is wrong here? Why does GCC complain?

Thanks!


Solution

  • Always pass va_list by value, never by pointer.

    Therefore:

    static int getIntValue(const int min, const int max, va_list vl)
    

    and

    initValues.uiFlags=getIntValue(INT_MIN, INT_MAX, vl);