On Thu, 9 Apr 2015, Florian Weimer wrote:

> If I declare a type with an _Alignas specification, requiring an
> alignment which is less than _Alignof (max_align_t), that is a,
> fundamental alignment, then I can allocate such an object with malloc.
> That is, this code is valid:
> 
>   struct S {
>     _Alignas (max_align_t) char a;
>   };

Subject to DR#444 (the C11 syntax currently doesn't actually allow 
_Alignas specifiers inside struct and unions at all).

>   struct S *p = malloc (sizeof (struct S));

For arrays of this type to work, sizeof (struct S) must actually be a 
multiple of its alignment (so 16, not 1).

> But I see nothing in the x86-64 ABI document that implies that malloc
> (1) must be 16-byte-aligned.  The fact that there are types of larger

It's C90 DR#075 that requires malloc (1) to return a pointer suitably 
aligned for all types (including long double).  (That is, all types that 
can be defined using C90 standard syntax.)

> Before C11, this was perfectly conforming.  I doubt it was the intention

No, it was never conforming for malloc (1) to return memory not aligned 
for long double.

All C11 (+ DRs) does is restrict the requirement from *all* types to all 
types that aren't over-aligned, along with introducing the possibility of 
over-aligned types.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to