[cpp-threads] RE: volatile, memory models, threads

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Mar 1 11:56:39 GMT 2006


"Peter Dimov" <pdimov at mmltd.net> wrote:
> 
> Right, and it is the object representation that is the subject of 3.9.3/1.
> "shall have the same representation and (alignment requirements)." Object
> representation includes size (among other things).

Well, you may be right, but there is nothing that you have quoted that
states (or even implies) that 3.9.3/1 refers to the object representation
rather than the value representation.  My assertion is that it can be
read either way, and the footnote strongly implies the latter.

> No. sizeof(x) is always the same when x is of type cv X, no matter whether x
> is an argument, return value, or part of an array, and the object
> representation of x is always the sequence of sizeof(x) == sizeof(X) bytes,
> starting from &x. It may well be the case that physically, padding is 
> inserted between x1 and x2 so that the arguments occupy more space than they 
> would otherwise, but this doesn't change the representation of x1 or x2. A 
> conforming program is still allowed to inspect the object representation 
> byte by byte (or copy it into another object of the same type for PODs.) 

Firstly, I said size and I meant size.  The value returned by sizeof
is NOT always the number of bytes occupied by an object, where that
object is an argument or return value (or potentially, a member of a
union).  The reason that can differ from the sizeof value is that it
is not possible to have an array of any of those, and therefore no
pointer arithmetic can be done on their addresses.

The result of this is that the actual size of the object is never
visible to a strictly conforming program, and so the implementations
can use the "as if" rule.  Some early ones implemented sizeof to be
the actual size of the object but, as far as I know, all current ones
have corrected that to be the normal size of the object.

Seriously.

Secondly, where is what you claim above stated as a requirement?

I have already SAID that it is implied by the ability to add qualifiers.
I repeat my apology for creating unnecessary confusion, but I also
repeat my assertion that the ONLY way in which cv-qualified types are
required to have the same size (in the sizeof sense) is because such
qualifiers can be added.  Drop that and there is NOTHING that I know
of IN THE STANDARD stopping them from being different sizes.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the cpp-threads mailing list