This is the mail archive of the gcc@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: aliasing



The relevant paragraph is in [basic.lval] of the C++ standard.  The
paragraph in the C standard is nearly identical.  Here it is.  Perhaps
someone would like to HTML-ify this, and make a FAQ entry out of it?

  If a program attempts to access the stored value of an object
  through an lvalue of other than one of the following types the
  behavior is undefined:

  --the dynamic type of the object,

You can access an object using the type it really has.  (I.e., you can
use an `int *' to refer to an `int'.)

  --a cv-qualified version of the dynamic type of the object,

You can also use a `const int *' to read an `int'.

  --a type that is the signed or  unsigned  type  corresponding  to  the
    dynamic type of the object,

Or an `unsigned int *'.

  --a  type  that  is the signed or unsigned type corresponding to a cv-
    qualified version of the dynamic type of the object,

Or a `const unsigned int *'.

  --an aggregate or union type that includes one of  the  aforementioned
    types among its members (including, recursively, a member of a
    sub-aggregate or contained union),

You can read or write an entire structure, thereby accessing all of
its fields.

  --a type that is a (possibly cv-qualified)  base  class  type  of  the
    dynamic type of the object,

This one is C++-specific.  You can read or write an entire base class
of the actual type of the object.

  --a char or unsigned char type.

You can use a `char *', `unsigned char *', `volatile char *',
`unsigned const volatile char *', etc. to read or write from anywhere.

All pointer types here can be replaced with reference types as well.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

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