mailing list of musl libc
 help / color / mirror / code / Atom feed
* max_align_t mess
@ 2014-06-23  4:48 Rich Felker
  2014-06-23  7:51 ` Szabolcs Nagy
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2014-06-23  4:48 UTC (permalink / raw)
  To: musl

Sometime we need to decide what to do about max_align_t. The GCC
definition is:

typedef struct {
  long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
  long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
} max_align_t;

Unfortunately, this definition is relying on bugs in GCC to give the
"right" result (the result they want and that matches the existing
ABIs), and is not reproducible in any portable manner: they're relying
on __alignof__(T) to give the preferred alignment of T rather than the
required alignment of T, and the portable (C11) _Alignof will not give
this result except on old buggy GCC.

One sane way to handle this might be to just put max_align_t in the
arch-specific alltypes.h fragment and use the following definition:

TYPEDEF struct { _Alignas(N) struct { char __align_c[M]; }; } max_align_t;

where N and M are the correct alignment and size for the arch ABI.

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: max_align_t mess
  2014-06-23  4:48 max_align_t mess Rich Felker
@ 2014-06-23  7:51 ` Szabolcs Nagy
  2014-06-23 17:11   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2014-06-23  7:51 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@libc.org> [2014-06-23 00:48:07 -0400]:
> 
> TYPEDEF struct { _Alignas(N) struct { char __align_c[M]; }; } max_align_t;
> 
> where N and M are the correct alignment and size for the arch ABI.
> 

I like this but unfortunately it only works if the compiler has _Alignas


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: max_align_t mess
  2014-06-23  7:51 ` Szabolcs Nagy
@ 2014-06-23 17:11   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2014-06-23 17:11 UTC (permalink / raw)
  To: musl

On Mon, Jun 23, 2014 at 09:51:35AM +0200, Szabolcs Nagy wrote:
> * Rich Felker <dalias@libc.org> [2014-06-23 00:48:07 -0400]:
> > 
> > TYPEDEF struct { _Alignas(N) struct { char __align_c[M]; }; } max_align_t;
> > 
> > where N and M are the correct alignment and size for the arch ABI.
> > 
> 
> I like this but unfortunately it only works if the compiler has _Alignas

Since max_align_t can only be defined portably with C11, I think it's
reasonable to expose it only under __STDC_VERSION__ >= 201112L. Or we
could add an #elif __GNUC__ using __attribute__((__aligned__)) but
from a namespace standpoint it's probably preferable to hide it for
pre-C11 anyway.

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-23 17:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-23  4:48 max_align_t mess Rich Felker
2014-06-23  7:51 ` Szabolcs Nagy
2014-06-23 17:11   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).