C++ Logo

std-discussion

Advanced search

Alignment and addresses

From: Bernhard Manfred Gruber <bernhardmgruber_at_[hidden]>
Date: Thu, 6 Jul 2023 00:54:40 +0200
Hi,

I am trying to figure out where the standard, specifically the object
model, defines alignment and its requirements on addresses.

In [basic.align]#1 it says:
Object types have alignment requirements ([basic.fundamental],
[basic.compound]) which place restrictions on the addresses at which an
object of that type may be allocated. An alignment is an
implementation-defined integer value representing the number of bytes
between successive addresses at which a given object can be allocated.

I am surprised by the second sentence, that the alignment of a type is the
difference between two addresses at which objects of this type can be
placed. It says nothing on the value of the addresses themselves. For that
matter, values of type double could be allocated at the addresses 0x1, 0x9,
0x11, 0x19, etc.

Digging deeper, I started wondering if the definition of alignment is vague
out of necessity, because it seems the standard also does not define
whether an address is an integer. It is described in various places that an
address (represented by a pointer) can be value-preservingly converted to
an integer and back, but that does not describe the nature of an address.

In any way, I would be glad if someone could point me to the right place
that establishes that alignment, which is defined as an integer, requires a
divisibility of an address by that number.

Thanks a lot!
Bernhard

Received on 2023-07-05 22:54:54