C++ Logo


Advanced search

Subject: Re: [ub] type punning through congruent base class?
From: Kazutoshi Satoda (k_satoda_at_[hidden])
Date: 2014-01-16 22:21:55

On 2014/01/17 12:57 +0900, Kazutoshi Satoda wrote:
> (Note)
> In C, there is no such a thing like "an object of type int" unlike in
> C++ where an object has a type and the type is determined when the
> object is created. In C, "object" is a merely a region of data storage,
> and may be labeled by an effective type which is determined by ongoing
> or previous access to the object at a time.
> If "struct B x = *p" follows the above code, the access (lvalue
> conversion, p2) on *p, which is allowed by the aliasing rule
> (6.5 p7, bullet 5 "an aggregate or union ..."), changes the effective
> type of the object at p.

Uh, sorry. I was wrong here. Non-modifying access to an object doesn't
change the effective type of subsequent access to the object. And the
aliasing rule does not apply here.

Let me correct the last paragraph.

If "struct B x = {0}; *p = x;" follows the above code, the write on *p
changes the effective type of the object at p (from int to B) for
subsequent non-modifying access of that object. (6.5 p6, about an
object having no declared type)


SG12 list run by herb.sutter at gmail.com