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: mark at markmitchell dot com
- Subject: Re: Your June 7 change to expand_expr
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- Date: Wed, 1 Jul 98 21:54:11 EDT
- Cc: egcs-bugs at cygnus dot com, jfc at mit dot edu, law at cygnus dot com, wilson at cygnus dot com
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.
This is very similar to Ada except that:
o References can be NULL in (pathalogical) erroneous programs, but I
believe that's probably true in C++ too, if you're technical about it.
o You cannot take the address of a reference from user code, but its
address will be taken automatically in the case of an up-level
reference from a nested function; I suspect this is also true for C++.
A major difference is that in C++, REFERENCE_TYPEs correspond to a specific
piece of language syntax, while in Ada, they are generated internally when
needed by some language constructs. Another example besides renaming is
top-level variable-length objects: they are allocated on the heap and the
variable becomes a reference to the object.