varargs historical regression question
Frank Griffin
ftg@roadrunner.com
Tue Sep 25 01:11:00 GMT 2012
I'm having a hard time googling/searching for anything that would
explain this, and I was hoping that the description might stir a memory
in some of those with some history here.
It involves varargs-related code which should never have worked, and in
fact does not work in 4.7.2, but appears to have worked in older GCC
versions as well as current (VS2008+) MS Visual C/C++.
The code example is something like this:
void *f1( int x, ... )
{
va_list args;
va_start( args, x );
f2( x, args );
f3( x, args );
var_end( args );
return;
}
void *f2( int x, va_list args )
{
va_arg( args, int );
return;
}
void *f3( int x, va_list args )
{
va_arg( args, int );
return;
}
The idea is that f1() creates a va_list from its variable-length
parmlist, and passes it to f2() which advances the internal va_list
pointer by referencing the first parameter via va_arg(). Then f3()
references a parameter via va_arg() which should get it the second
parameter in the variable list.
Except in the older versions we've used to build our product (2.9.9
definitely, 3.4.6 pretty sure), it doesn't --- f3() sees the first
va_list parameter, not the second. Our code mistakenly assumed this to
be the case, and has been working happily. Of course, what it should
have done if f3() wanted to see the first parameter was something like:
void *f1( int x, ... )
{
va_list args;
va_list args2;
va_start( args, x );
va_copy( args2, args );
f2( x, args );
f3( x, args2 );
var_end( args );
var_end( args2 );
Can anyone confirm this or shed any light thereupon ? I'll have to do
the testing to verify that the corrected code works when built with the
older compilers and so forth, but I'd be interested to know if this was
a known problem and at what point it was corrected.
return;
}
More information about the Gcc-regression
mailing list