C++ Logo

std-discussion

Advanced search

Re: Alignment and addresses

From: Brian Bi <bbi5291_at_[hidden]>
Date: Wed, 5 Jul 2023 19:46:50 -0400
On Wed, Jul 5, 2023 at 6:54 PM Bernhard Manfred Gruber via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> 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.
>

Correct.


>
> 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.
>

For the reasons above, such a requirement would not be well-defined, and
therefore, does not exist in the standard.


>
> Thanks a lot!
> Bernhard
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>


-- 
*Brian Bi*

Received on 2023-07-05 23:47:05