[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_CHECK_ALIGNOF maximum ??

From: Nick Bowler
Subject: Re: AC_CHECK_ALIGNOF maximum ??
Date: Thu, 20 Jun 2013 11:27:41 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On 2013-06-20 16:12 +0100, 'Chris Hall' wrote:
> Bob Friesenhahn wrote (on Thu 20-Jun-2013 at 15:19 +0100):
> > On Thu, 20 Jun 2013, 'Chris Hall' wrote:
> ...
> > >  AC_CHECK_ALIGNOF (type, [includes = ?AC_INCLUDES_DEFAULT?])
> > >
> > > which is quite lovely, as far as it goes... but it does not appear
> > > to tell me the maximum possible alignment.
> > >
> > > Of course gcc gives __BIGGEST_ALIGNMENT__ for this.  And I guess
> > > other compilers do something similar...
> > and for what purpose would you use this information for?
> Specifically... I want to allocate lumps of memory with some red tape
> in front to be followed by the "body" of the allocation.  That body
> needs to be aligned, as if by malloc, to the maximum alignment.
> For completeness, given the sizeof() the body I wish to align to
> sizeof() % maximum alignment.
> With C11 I could use the alignof() spell to do something more precise.
> And I guess I could Autoconf my way to discovering if __alignof__() or
> equivalent whizzy-ness is available.

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;

You could use AC_CHECK_TYPE to test for max_align_t, then use
AC_CHECK_ALIGNOF on the above monster if it is not available.

You may also want to test for long long availability before
including it in the union...

Nick Bowler, Elliptic Technologies (

reply via email to

[Prev in Thread] Current Thread [Next in Thread]