Section 5.2.2.7 of the C ++ 03 standard states that lvalue-rvalue conversion is done first, so your function should get a copy of int instead of a link.
I tried this with this program using g ++ 4.6.3:
#include <iostream>
#include <stdarg.h>
int g_myInt = 7;
int& getIntReference() { return g_myInt; }
void myVarArgFunction( int a, ... )
{
va_list ap;
va_start(ap,a);
int value = va_arg(ap,int);
va_end(ap);
std::cerr << value << "\n";
}
int main(int,char **)
{
myVarArgFunction( 0, getIntReference() );
return 0;
}
And got the result 7.
source
share