Old Wolf said:
Keith said:
A C implementation *must* allow char objects to be stored at odd byte
addresses. It can choose to align all single declared char objects,
or even char struct members, at even addresses if that makes access
easier or faster, but there can be no padding between array elements:
char arr[2];
/* either arr[0] or arr[1] is at an odd byte address */
If the hardware doesn't allow this (or makes it too expensive), then
the implementation can make bytes bigger than 8 bits.
How do you define "odd byte address" ?
I don't see why you can't have 16-bit bytes, at addresses 0, 2, 4, ...
Actually, I don't define "odd byte address" -- but the standard does
implicitly use the concept without defining it. C99 3.2 defines the
term "alignment":
alignment
requirement that objects of a particular type be located on
storage boundaries with addresses that are particular multiples of
a byte address
Strictly speaking, 0, 2, 4, ... are not addresses; they're integers.
(void*)0, (void*)2, (void*)4, ... are addresses, but the standard
tells us nothing about their representation. On some systems I've
used (Cray vector systems), machine addresses point to 64-bit words,
but CHAR_BIT==8, and void* and char* have extra offset information.
An pointer object whose representation looks like an odd integer might
point to what I'd call an even byte address, and an pointer object
whose representation looks like an even integer might point to what
I'd call an odd byte address.
My assumption is that if p is an even address, then p+1 is an odd
address (assuming p is a character pointer), regardless of the
representation; I think that's the only model that's consistent with
the standard's concept of "alignment".