This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Your June 7 change to expand_expr


    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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]