On 09/06/2016 11:23 AM, Richard Biener wrote:

The question then is, how can we make max_align_t more useful?  If it is
supposed to reflect a malloc property, it cannot be a compile-time constant
because we don't know at compile time which malloc is going to be used
(malloc has to remain interposable).  If there is no relationship to malloc,
GCC essentially supports unbounded alignment on many targets.  How is it
possible to have a meaningful definition of max_align_t under such
circumstances?

I thought max_align_t was to replace uses like

  union {
    long long x;
    double y;
    ...
    char buf[N];
  };

to get statically allocated "max" aligned memory.  That is, you now know
_which_ type you need to put into the union.

Yes, that's the way I have used it too. But it's difficult to use such an idiom and make it valid C11 (you basically have to use memcpy to access the buffer, direct access is not permitted because the dynamic type is char).

But it's unclear what this trying to achieve. Ignoring the aliasing issue, you can store any object there if you haven't used an _Alignas specification. If you used an _Alignas specification for the object's type, you may have to manually align the pointer if the alignment is larger than that of max_align_t.

The existence of such a cut-off constant appears useful, but it's not clear if it should be tied to the fundamental alignment (especially, as this discussion shows, the fundamental alignment will be somewhat in flux).

Florian

Reply via email to