Conversely, if any declaration of an entity has an
alignment-specifier,
every defining
declaration of that entity shall specify an equivalent alignment
. No diagnostic is required if declarations of an entity have
different
alignment-specifiers
in different translation units
. [
Example 2:
struct S { int x; } s, *p = &s;
struct alignas(16) S;
extern S* p;
—
end example]
[
Example 3:
An aligned buffer with an alignment requirement
of A and holding N elements of type T
can be declared as:
alignas(T) alignas(A) T buffer[N];
Specifying
alignas(T) ensures
that the final requested alignment will not be weaker than
alignof(T),
and therefore the program will not be ill-formed
. —
end example]
[
Example 4:
alignas(double) void f();
alignas(double) unsigned char c[sizeof(double)];
extern unsigned char c[sizeof(double)];
alignas(float)
extern unsigned char c[sizeof(double)];
—
end example]