go***********@burditt.org (Gordon Burditt) wrote:
6.2.5.6 says:
"For each of the signed integer types, there is a corresponding (but
different) unsigned integer type (designated with the keyword
unsigned) that uses the same amount of storage (including sign
information) and has the same alignment requirements."
However, I can't find any definition of the alignment requirements of
a given type via full-text search.
They are implementation-defined.
long long m = 0x12345678ABABCDCDLL;
long long* p = &m;
bool b = ((int)p) % 8);
There is no guarantee that sizeof(long long) = 8, nor that the alignment
of a long long has anything to do with the number 8.
However, there is a guarantee that the alignment of any type has
something to do with sizeof(that type). It is not possible for the
alignment requirements of <typeto be stricter (i.e., for <typeto be
required to be aligned on a larger amount of bytes) than sizeof(<type>),
because in a <typearray[], array[1] must have the address of array[0]
plus exactly sizeof(<type>) bytes.
It _is_ allowed for <type>'s alignment to be less restrictive than
sizeof(<type>), as Gordon already implied, and it's even allowed
(although I've never seen any such system, and would be highly surprised
if it existed) for <typeto need to be aligned to an address which, if
converted to a intptr_t, to be equal to N*sizeof(<type>)+(a constant <
sizeof(<type>) but >0).
That, I think, is all that's required. It isn't much.
Richard