Topic: Defect Report: Layout compatible structs
Author: "Bill Wade" <bill.wade@stoner.com>
Date: 2000/02/05 Raw View
9.2 [class.mem] paragraph 14 reads
"Two POD-struct (clause 9) types are layout compatible if they have the same
number of members, and corresponding members (in order) have layout
compatible types (3.9)."
This seems to be overly restrictive. Static members, and non-virtual
function members should not affect layout compatibility. I expect that the
intent of the statement would be clearer if the paragraph where changed to
"Two POD-struct (clause 9) types are layout compatible if they have the same
number of non-static data members, and corresponding non-static data members
(in order) have layout compatible types (3.9)."
3.9 [basic.types] paragraphs 2 and 3 discuss the semantics of using memcpy
with POD objects. They essentially say that copying between POD objects of
type T with memcpy (directly, or indirectly through an array of char) copies
the source object's value. It would be nice if there were an explicit
guarantee that for
T1 t1;
T2 t2;
where T1 and T2 are layout compatible POD structs (or unions) that after
memcpy(&t1, &t2, sizeof(t1));
corresponding members of t1 and t2 would have the same value. I assume that
is the intended meaning of layout compatible, but I can't find it in the
standard.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]