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

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


"Peter Dimov" <pdimov at mmltd.net> wrote:
>
> > ALL that is needed to allow an implementation to support any POD type
> > as atomic is to allow it to add a lock flag to that object, but that
> > means allowing an atomic type to be of different size to the
> > unqualified type.  This is already allowed in one section, except
> > that the ability to lose qualifiers makes it unimplementable!
> 
> You keep saying that, but it simply isn't true. Objects of cv-qualified 
> types have the same representation and alignment as objects of the 
> cv-unqualified types (3.9.3/1), and representation in this context includes 
> size (3.9/4). And of course the ability to _add_ qualifiers, which is a 
> pretty basic part of the language (char* to char const*), also requires it, 
> not only the ability to lose them. 

What you have just posted isn't true, I am afraid, but it is my fault
for creating a large amount of unnecessary confusion.  Let's start at
the back.

"And of course the ability to _add_ qualifiers," - mea culpa.  Sorry.
I got it right in some of my previous postings.  It is the other way
round!  Losing qualifiers is already forbidden (e.g. 5.2.7/5).

3.9/4 defines "object representation" and "value representation", but
3.9.3/1 refers to the "representation requirements".  The footnote
clarifies that this is intended to imply interchangeability as
arguments, return values and members of unions.  Now, it may surprise
you, but there have been (and probably still are) implementations
where arguments and return values are different sizes from the SAME
value in ordinary objects.  That is possible and permitted.  A similar
thing is possible in unions, though I have not seen it done.

Where I created considerable confusion in my first point was in not
making it clear that the ability to ADD qualifiers DOES mean that the
sizes must be the same.  This isn't required by explicit wording, but
is required for consistency with the rest of the standard.  But that
is the only way in which the sizes are constrained to be the same.


This is why I am saying that the simple change of forbidding the atomic
qualifier to be added (as well as the already forbidden lost), means
that the sizes could be different.

Obviously, it would be worth changing footnote 46 to clarify this, but
that is a mere informative change.


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