Hello all,

If anyone is interested, I would like to discuss the warning:
        warning: second parameter of 'va_start' not last named argument


I have the following declaration:
   void fl_information(const char *fmt, const char *title, ...);

Where, "fmt" specifies the printf-style format string (e.g. "You are %d 
year(s) old). "title" specifies the window title. Finally, the variadic 
(sp?) is to be applied to "fmt".

The implementation for this function is as follows:

void fl_information(const char *fmt, const char *title, ...)
{
   va_list ap;
   va_start(ap, fmt);

   if(!title)
      title = "Information";

   dialogbox(0, 0, title, &image_dialog_information, fmt, ap);
}

When I compile this function I get the following (AFAIK, correct) warning:

warning: second parameter of 'va_start' not last named argument

I have compared my function to how fl_choice() is defined and compiles in 
fl_ask.cxx.

I have since figured out that I am using "va_start" incorrectly. According 
to this URL[1] the 2nd argument of va_start is used for positional 
information (it's content is not used). So:
   va_start(ap, fmt)

Indicates that the additional arguments (the variadic) start after fmt. 
Which is obviously wrong!

I see that in fl_choice(), the correct 2nd arguments is used. In that case:
   va_start(ap, b2);

And therefore, I should be using:
   va_start(ap, title);


Now, I understand how to use va_start (I hope).

However, does anyone know why the 2nd argument is needed at all? I mean, if 
the compiler knows what the last argument is, why have the programmer even 
specify it at all? If you go to this URL[2] and scroll to the 3rd HUNK of 
the diff, you will see this:

        if (arg != last_parm)
        warning ("second parameter of `va_start' not last named argument");

Now, I haven't checked the entire source where this patch applies, but it 
appears to me that in order to issue the warning in the first place, gcc was 
able to figure out what the true last parameter is (e.g. last_parm). So, if 
it can do that, why not just require the programmer to use:
   va_start(ap);

Could this just be a throw-back from back in the day when gcc didn't produce 
this error because it couldn't figure out what the true last parameter was?

Cheers,

Alvin


[1] http://www.cplusplus.com/reference/clibrary/cstdarg/va_start/
[2] http://gcc.gnu.org/ml/gcc-patches/2003-05/msg01840.html





_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to