int g_myInt = 0;
int& getIntReference() { return g_myInt; }
void myVarArgFunction( int a, ... ) {
// .........
}
int main() {
myVarArgFunction( 0, getIntReference() );
return 0;
}
In the (uncompiled and untested) C++ code above, is it valid to pass in an int& into a variable argument list? Or is it only safe to pass-by-value?
Section 5.2.2.7 of the C++03 standard says that lvalue-to-rvalue conversion is first performed, so your function should receive a copy of the int instead of a reference.
I tried it with this program using g++ 4.6.3:
And got an output of 7.