Quantcast
Channel: C++ guarantee and name for POD-like data, memcpy capable - Stack Overflow
Viewing all articles
Browse latest Browse all 5

C++ guarantee and name for POD-like data, memcpy capable

$
0
0

In another question I incorrectly used the term POD to refer to data types that aren't actually POD types (on account of having a constructor). Now, I've looked through the standard and couldn't find a proper name for what I want. Nor can I actually find a guarantee that copying is actually allowed.

The data type I mean is a POD, but may contain functions, including constructors, but nothing that should alter its alignment or size characteristics when compared to an equivalent POD type.

In section 3.9 of the standard it states that POD data can be copied with memcpy, either to another object, or to character data and back. No such guarantee is ever made of non-POD data.

However, the object representation of an object is defined in the same section. It is defined such that one would believe any two objects of the same type could be safely copied via memcpy.

So my questions are:

  1. Is the copy with memcpy actually guaranteed to be safe for such objects?
  2. If yes, then why is there a special note about memcpy and POD?
  3. Is there a name for this type of data which is memcpy safe?

A simple example of the type of object I mean:

struct ex_struct{  int a,b,c,d;  ex_struct() : a(123) { }}

Reading the C++0x draft, my struct would appear to be a trivially copyable class (9.1). I believe that implies memcpy would be safe.


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images