CBFalconer said:
If, for example, the basic element is an array of 3 bytes, but
requires the alignment of 4, the individual element will be padded
with an extra byte. Something like:
typedef struct elem {
int i;
char c;
} elem;
Yes, but this really has nothing much to do with the array itself. This
trailing padding exists as an integral part of the above struct, not as
something inserted additionally _between_ the elements of the array and
specific to the the array itself.
For arrays, the following relation must hold
sizeof array = sizeof element * number_of_elements
This eliminates any possibility of the array inserting any additional
padding between its elements. Any necessary padding should be already
present in the element itself (in terms of it size, as returned by
'sizeof').
and, to me, each element of:
elem array[MAX};
will be padded accordingly. This is why such arrays cannot be
compared for equality with simple code.
I'm not really sure what exactly you mean here. But if you are saying
that arrays can't be compared by raw memory comparison because padding
areas might contain unpredictable bit patterns, then first of all this
issue actually already applies to structs. It already exists for
standalone structs, no arrays necessary. And it applies to arrays of
structs just as mere consequence of that, not because of some specific
property of arrays.
If array elements contain no padding of any kind (i.e. if they can be
compared by raw memory comparison), then whole arrays of such elements
can also be compared by raw memory comparison because, once again,
arrays are not allowed to introduce any additional padding between their
elements.