|
|
Message-ID: <53dd583b-06b2-3503-7343-222c46c6ab64@ispras.ru>
Date: Sun, 21 Apr 2024 19:44:12 +0300 (MSK)
From: Alexander Monakov <amonakov@...ras.ru>
To: musl@...ts.openwall.com
Subject: Re: Alignment attribute in headers
On Sun, 21 Apr 2024, Thorsten Glaser wrote:
> Michael Forney dixit:
>
> >Something like
> >
> >#if __STDC_VERSION__ >= 201112L
> >/* use _Alignas */
> >#elif defined(__cplusplus) && !defined(__GNUC__)
> >/* use alignas */
> >#else
> >/* use __attribute__((__aligned__(N))) */
> >#end
>
> Something I noticed recently while doing m68k alignment work:
>
> The C++ alignas is UB if the specified alignment is smaller
> than what the structure would normally have, so adding cautious
> alignments can explode in one’s face. ☹ Not only is this really
> stupid, but makes it not generally usable, too.
>
> GCC’s attribute, in contrast, (without __packed__) just gets
> ignored for those cases.
This is inaccurate: you can use the attribute to decrease alignment
of scalar types (but you do need __packed__ when attaching the attribute
to a struct). As I recall, GCC documentation used to be misleading
or wrong about this, but the current wording is fairly clear to me:
When used on a struct, or struct member, the aligned attribute can
only increase the alignment; in order to decrease it, the packed
attribute must be specified as well. When used as part of a typedef,
the aligned attribute can both increase and decrease alignment, and
specifying the packed attribute generates a warning.
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
Alexander
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.