This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Your June 7 change to expand_expr
- To: kenner at vlsi1 dot ultra dot nyu dot edu
- Subject: Re: Your June 7 change to expand_expr
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Wed, 1 Jul 1998 15:32:04 -0700
- CC: wilson at cygnus dot com, egcs-bugs at cygnus dot com, jfc at mit dot edu, law at cygnus dot com
- References: <9807012139.AA17731@vlsi1.ultra.nyu.edu>
- Reply-to: mark at markmitchell dot com
>>>>> "Richard" == Richard Kenner <kenner@vlsi1.ultra.nyu.edu> writes:
Jim> In C++, a REFERENCE_TYPE points at an object. In
Jim> Ada, a REFERENCE_TYPE points into an object.
Richard> No. In Ada it's like a C pointer: it *can* point into an
Richard> object, but usually points at an object.
I'm not sure I know quite what you two mean by these words, but here's
my take, as one knowledgeable about C++:
A C++ reference type is precisely like a C pointer type, with a few
variations:
o References can never be NULL.
o References must be initialized and cannot be modified.
(You can modify the thing referred to, but cannot modify
which thing the reference refers to.)
o Similarly, you cannot take the address of a reference.
o You don't have to write (*r) to derefernce a reference,
and you write r. rather than r-> to use a reference to
a structure.
Other than that, there's no real difference. In particular, given
something like:
struct S {
int i;
} s;
which means in C++ just what it means in C, you can have:
struct S& sr = s; /* sr is a reference to s. */
int& ir = s.i; /* ir is a reference to s.i. */
So, I don't see a problem with Kenner using references in Ada. It
would be nice if references are always non-NULL in Ada, but I don't
think GCC yet makes use of this information in any way. Kenner is
correct; if we wish to mandate that any of the C++ reference
properties always hold for REFERENCE_TYPEs we should document that
clearly.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com