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]
Other format: [Raw text]

Re: ISO Aliasing rules question




--On Friday, February 21, 2003 09:20:32 PM +0100 Michael Matz <matz at suse dot de> wrote:

Hi,

On Fri, 21 Feb 2003, Mark Mitchell wrote:

--On Friday, February 21, 2003 08:38:07 PM +0100 Michael Matz
<matz at suse dot de> wrote:

> Yes, but he's accessing a member, not the whole struct.  And that
> access

I'm pretty sure it's the pointer he's using that's the key.

If he wrote:

double *dp = (double*) b;

*dp = 1.0;

that would be fine, but saying b->d = 1.0 isn't.

Hmm. How's that then:


double *dp = &(b->d);
*dp = 1.0;

This definitely is accessing a 'double' object, and aliases ergo with
a->d.  In this regard I fail to see the difference between
"*dp = 1.0" and "b->d = 1.0".

The point is that "b" doesn't point to what you're claiming it does.


The model goes like this:

(1) When you see ->, check that the object on the left of the -> has
   an effective type compatible with its static type.  If not, blow up.

(2) Having done that, access the data.

You're reversing the two steps, in some sense.

Another way to say this is that "x->y" is really short-hand for "(*x).y". The C++ stnadard explicitly says that the -> is just short-hand.

--
Mark Mitchell                mark at codesourcery dot 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]