--- Comment #51 from W.H. Ding <dingcurie at icloud dot com> ---
(In reply to Sven from comment #49)
> This doesn't work. The aligned attribute is for providing additional
> alignment hints. The GCC documentation clearly states, that aligned can
> increase the alignment. So g_d is still 4 byte aligned, and correctly so.
It's really confusing about using 'aligned' attributes in various situations.
Under the title "Specifying Attributes of Variables", the doc says "When used
as part of a typedef, the aligned attribute can both increase and decrease
alignment" without an example. While under the title "Specifying Attributes of
Types", the doc gives an example of typedef but states at the end "The aligned
attribute can only increase alignment."
So perhaps, my test case should have been:
typedef int unaligned_int __attribute__((aligned(1)));
char g_c = 'x';
unaligned_int g_d = 13;
g_c = 'z';
g_d = 33; // Crash on, in my case, ARM Cortex-M0
But the result is the same. After all, the 'aligned' attribute took effect in
either case since g_d is at an odd address as a consequence.