S
Siemel Naran
What do you mean by not well-defined?
What do these last 4 quotes have to do with padding? BTW, padding might be
addressed more fully in the C standard library, but I don't have that one.
... in general. There are special cases where *the same value* of
padding bits can be written as in the case of POD types:
"For any complete POD object type T, whether or not the object holds a
valid value of type T, the underlying
bytes (1.7) making up the object can be copied into an array of char or
unsigned char.36) If the content
of the array of char or unsigned char is copied back into the object,
the object shall subsequently
hold its original value.
[Example:
#define N sizeof(T)
char buf[N];
T obj; // obj initialized to its original value
memcpy(buf, &obj, N); // between these two calls to memcpy,
// obj might be modified
memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type
// holds its original value
—end example]
3 For any POD type T, if two pointers to T point to distinct T objects
obj1 and obj2, if the value of obj1
is copied into obj2, using the memcpy library function, obj2 shall
subsequently hold the same value as
obj1. [Example:
T* t1p;
T* t2p;
// provided that t2p points to an initialized object ...
memcpy(t1p, t2p, sizeof(T)); // at this point, every subobject of POD
type in *t1p contains
// the same value as the corresponding subobject in *t2p
—end example]
4 The object representation of an object of type T is the sequence of N
unsigned char objects taken up by
the object of type T, where N equals sizeof(T). The value representation
of an object is the set of bits
that hold the value of type T. For POD types, the value representation
is a set of bits in the object representation
that determines a value, which is one discrete element of an
implementationdefined
set of values.37)"
However as it can be seen in the last paragraph, for non-POD types we
can only *read* the objects as arrays of unsigned chars.
What do these last 4 quotes have to do with padding? BTW, padding might be
addressed more fully in the C standard library, but I don't have that one.