// Demonstration of difference between ANSI and Cfront rules // for binding references. Program prints "Cfront" when compiled // with Cfront rules, and "ANSI" when compiled by ANSI rules. #include char x, y; char *global_ptr; void Test( const char *const &ref ) { // Caller initialized ref to global_ptr, possible via a temporary. // Now change the value of global_ptr. global_ptr = &y; if( ref==&x ) { // Referenced pointer did not change - must be a temporary. cout << "ANSI\n"; } if( ref==&y ) { // Referenced pointer changed -- must be directly bound. cout << "Cfront\n"; } } main() { global_ptr = &x; // Under Cfront rules, the formal parameter ref is bound directly to // global_ptr. Under ANSI rules, the formal parameter ref is bound // to a temporary copy of global_ptr. Why the temporary? Because // direct binding is allowed [dcl.init.ref] only if the formal and // actual are "reference compatible". The ANSI rules allow only // top-level changes in qualifiers for making lvalues reference compatible. // No temporary would be generated if the 2nd-level qualifiers were changed // to match. I.e., if global_ptr were of type (const char *) or // ref were of type (char *const &). Test( global_ptr ); }