Movatterモバイル変換


[0]ホーム

URL:


Issue 43 - WG21 CWG Issues
Title
Copying base classes (PODs) using memcpy
Status
tc1
Section
6.9 [basic.types]
Submitter
Nathan Myers

Created on1998-09-15.00:00:00 last changed277 months ago

Messages

msg205 (view)
Date: 1999-04-15.00:00:00

Proposed Resolution (04/99):Change the text in 6.8 [basic.types]paragraph 2 from:

For any complete POD object typeT, ...
to:
For any object (other than a base class subobject) of POD typeT, ...
Change the text in 6.8 [basic.types] paragraph 3from:
For any POD typeT, if two pointers toTpoint to distinctT objectsobj1 andobj2,
to:
For any POD typeT, if two pointers toTpoint to distinctT objectsobj1 andobj2,where neitherobj1 norobj2 is a base class subobject,...
msg7 (view)
Date: 2022-11-20.07:54:16

Can you use memcpy on non-member POD subobjects of non-POD objects?

In 6.9 [basic.types]paragraphs 2 and 3 we have:

For any complete POD object typeT, whether or not the objectholds a valid value of typeT, the underlying bytes(6.8.1 [intro.memory]) makingup the object can be copied into an array ofcharorunsigned char*. If the content ofthe array ofchar orunsigned char is copied back into the object, theobject shall subsequently hold its original value.[Example elided]
*[Footnote: By using, for example, the library functions(16.4.2.3 [headers])memcpy ormemmove.end footnote]
For any POD typeT, if two pointers toT pointto distinctT objectsobj1andobj2, if the value ofobj1 is copied intoobj2, using thememcpy libraryfunction,obj2 shall subsequently hold the same value asobj1.
Paragraph 3 doesn't repeat the restriction of paragraph 2. Should it beassumed? Otherwise only complete POD types are copyable to an array ofchar and back, but scribbling over subobjects is OK.(Or perhaps a "distinctT object" is a complete object...)

Proposed Resolution (04/99):Change the text in 6.9 [basic.types]paragraph 2 from:

For any complete POD object typeT, ...
to:
For any object (other than a base class subobject) of POD typeT, ...
Change the text in 6.9 [basic.types] paragraph 3from:
For any POD typeT, if two pointers toTpoint to distinctT objectsobj1 andobj2,
to:
For any POD typeT, if two pointers toTpoint to distinctT objectsobj1 andobj2,where neitherobj1 norobj2 is a base class subobject,...
History
DateUserActionArgs
2003-04-25 00:00:00adminsetstatus: dr -> tc1
1999-09-14 00:00:00adminsetmessages: +msg205
1999-09-14 00:00:00adminsetstatus: review -> dr
1998-09-15 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp