4 ms·
This is documented as not working[1] in all but the most recent GCC versions. E.g. gcc-5.4 documents: > "The aligned attribute can only increase the alignment;
by stephencanon 10y ago
This is documented as not working[1] in all but the most recent GCC versions. E.g. gcc-5.4 documents:
> "The aligned attribute can only increase the alignment; but you can decrease it by specifying packed as well. See below."
but gcc-6.2 documentation adds:
> "When used as part of a typedef, the aligned attribute can both increase and decrease alignment, and specifying the packed attribute generates a warning."
FWIW, Clang has supported reducing alignment in this fashion for a few years now.
[1] it's possible (likely, even) that it has been working for a while but the documentation was only recently brought up to date; I haven't investigated too carefully.
- qb45 10y agoMust have been supported for a while because this stuff is even used in Linux: #define __packed2__ __attribute__((packed, aligned(2))) /* * SystemV FS comes in two variants: * sysv2: System V Release 2 (e.g. Microport), structure elements aligned(2). * sysv4: System V Release 4 (e.g. Consensys), structure elements aligned(4). */ struct sysv2_super_block { __fs16 s_isize; /* index of first data zone */ __fs32 s_fsize __packed2__; /* total number of zones of this fs */ http://lxr.free-electrons.com/source/include/linux/sysv_fs.h#L98 http://lxr.free-electrons.com/source/include/linux/sysv_fs.h...
- codys 10y agoNote the use of `packed`. `packed` causes the alignment to be set as small as possible (1 byte). The aligned(2) that follows then increases the alignment from 1 byte to 2 bytes.
- qb45 10y agoYeah, you're right. Add packed then if you want but I swear the code I posted works on 5.4 as it is.