* ANSI vs Cfront binding
@ 1997-12-01 13:23 Ross Alexander
0 siblings, 0 replies; only message in thread
From: Ross Alexander @ 1997-12-01 13:23 UTC (permalink / raw)
To: egcs
A friend of mine showed me this piece of code. I was interesting on
any comments people had and what should be expected in the future
(with respect to ANSI/ISO compliance).
----------------------------------------------------------------------
// 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 <iostream.h>
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 );
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1997-12-01 13:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-01 13:23 ANSI vs Cfront binding Ross Alexander
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).