G
Gianni Mariani
What does the standard say about this code ...
#include <iostream>
const char * func( const char * v )
{
std::cout << "func called with v = " << v << "\n";
return v;
}
void zoo( const char * v )
{
static const char * sv( func( v ) ); // What happens here on SECOND?
std::cout << "zoo called with v=" << v << " sv=" << sv << "\n";
}
int main()
{
zoo( "FIRST" );
zoo( "SECOND" );
}
gcc 3.4.0 and MS C++ 7.1 give me:
func called with v = FIRST
zoo called with v=FIRST sv=FIRST
zoo called with v=SECOND sv=FIRST
This means that the initializer expression for static variables is
initialized only once. Tricky.
Has anyone seen problems with compilers getting this wrong ?
#include <iostream>
const char * func( const char * v )
{
std::cout << "func called with v = " << v << "\n";
return v;
}
void zoo( const char * v )
{
static const char * sv( func( v ) ); // What happens here on SECOND?
std::cout << "zoo called with v=" << v << " sv=" << sv << "\n";
}
int main()
{
zoo( "FIRST" );
zoo( "SECOND" );
}
gcc 3.4.0 and MS C++ 7.1 give me:
func called with v = FIRST
zoo called with v=FIRST sv=FIRST
zoo called with v=SECOND sv=FIRST
This means that the initializer expression for static variables is
initialized only once. Tricky.
Has anyone seen problems with compilers getting this wrong ?