Nick Bowler wrote (on Thu 20-Jun-2013 at 19:06 +0100):
> On 2013-06-20 10:51 -0700, Russ Allbery wrote:
> > Nick Bowler <nbow...@elliptictech.com> writes:
> > > C11 also provides max_align_t, which is *probably* what you are
> > > looking for but obviously isn't available everywhere.  Anyway,
> > > on older implementations without max_align_t, the following
> > > type is probably a "good enough" substitute for it:
> > >
> > >   union {
> > >     char a;
> > >     short b;
> > >     int c;
> > >     long d;
> > >     long long e;
> > >     float f;
> > >     double g;
> > >     long double h;
> > >     void *i;
> > >   }

> > I would add a function pointer, but yes.

> Good idea.

Hmmm.  Up to a point...

...I confess this approach makes me feel more than a little queasy.  I
checked the C99 standard and the above appears to cover all the types
mentioned in 6.2.5... except for _Bool (!).  I note that the _Complex
types are defined to have the same alignment as the corresponding
floats.  Similarly unsigned integers are defined to align the same as
the corresponding signed ones.  There's wchar_t, size_t, intptr_t, ...
which I suppose one is justified in supposing are the same as one of
the ordinary integers.  But then there are the "implementation defined
extended integer types"... which aren't on the list, of course --
uint256_t, anybody ?  (I cannot spot anything in the standard which
says that long long is definitely bigger than long, or that it
definitely has a larger alignment... similarly long double etc...
otherwise the list could be shortened somewhat.)

...I cannot help feeling that this would be wonderfully portable,
except where it wasn't -- and in the second of these cases you'd be in
it up to your neck, without warning.
 
Actually, for what I am trying to do, I have decided to fake
alignof().  It takes a bit of dicking-about, but it occurred to me
that alignof(foo_t) may be constructed as offsetof(struct { char x;
foo_t q; }, q)... Sadly gcc throws an unhelpful (in this case)
warning... which requires some scrubbing around :-(

Thanks,

Chris


_______________________________________________
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf

Reply via email to