https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88085

--- Comment #18 from Petro Karashchenko <petro.karashchenko at gmail dot com> 
---
Yes. So I just checked GCC man and see that

The aligned attribute can only increase the alignment; but you can decrease it
by specifying packed as well. See below.

Note that the effectiveness of aligned attributes may be limited by inherent
limitations in your linker. On many systems, the linker is only able to arrange
for variables to be aligned up to a certain maximum alignment. (For some
linkers, the maximum supported alignment may be very very small.) If your
linker is only able to align variables up to a maximum of 8 byte alignment,
then specifying aligned(16) in an __attribute__ will still only provide you
with 8 byte alignment. See your linker documentation for further information.

So

typedef int tolerant_int __attribute__((aligned(1)));
extern tolerant_int possibly_misaligned_data;

"possibly_misaligned_data" will still be 4 bytes aligned.

The real problem is that "packed" can be applied only to struct or union type
definition, I can't just do

typedef int tolerant_int __attribute__((packed));
extern tolerant_int possibly_misaligned_data;

So it will simply not work and I need to wrap a variable into a struct or
union.

Reply via email to