Blame gl/stdalign.in.h

Packit 549fdc
/* A substitute for ISO C11 <stdalign.h>.
Packit 549fdc
Packit 549fdc
   Copyright 2011-2016 Free Software Foundation, Inc.
Packit 549fdc
Packit 549fdc
   This program is free software; you can redistribute it and/or modify
Packit 549fdc
   it under the terms of the GNU Lesser General Public License as published by
Packit 549fdc
   the Free Software Foundation; either version 2.1, or (at your option)
Packit 549fdc
   any later version.
Packit 549fdc
Packit 549fdc
   This program is distributed in the hope that it will be useful,
Packit 549fdc
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 549fdc
   GNU Lesser General Public License for more details.
Packit 549fdc
Packit 549fdc
   You should have received a copy of the GNU Lesser General Public License
Packit 549fdc
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 549fdc
Packit 549fdc
/* Written by Paul Eggert and Bruno Haible.  */
Packit 549fdc
Packit 549fdc
#ifndef _GL_STDALIGN_H
Packit 549fdc
#define _GL_STDALIGN_H
Packit 549fdc
Packit 549fdc
/* ISO C11 <stdalign.h> for platforms that lack it.
Packit 549fdc
Packit 549fdc
   References:
Packit 549fdc
   ISO C11 (latest free draft
Packit 549fdc
   <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>)
Packit 549fdc
   sections 6.5.3.4, 6.7.5, 7.15.
Packit 549fdc
   C++11 (latest free draft
Packit 549fdc
   <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>)
Packit 549fdc
   section 18.10. */
Packit 549fdc
Packit 549fdc
/* alignof (TYPE), also known as _Alignof (TYPE), yields the alignment
Packit 549fdc
   requirement of a structure member (i.e., slot or field) that is of
Packit 549fdc
   type TYPE, as an integer constant expression.
Packit 549fdc
Packit 549fdc
   This differs from GCC's __alignof__ operator, which can yield a
Packit 549fdc
   better-performing alignment for an object of that type.  For
Packit 549fdc
   example, on x86 with GCC, __alignof__ (double) and __alignof__
Packit 549fdc
   (long long) are 8, whereas alignof (double) and alignof (long long)
Packit 549fdc
   are 4 unless the option '-malign-double' is used.
Packit 549fdc
Packit 549fdc
   The result cannot be used as a value for an 'enum' constant, if you
Packit 549fdc
   want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc.
Packit 549fdc
Packit 549fdc
   Include <stddef.h> for offsetof.  */
Packit 549fdc
#include <stddef.h>
Packit 549fdc
Packit 549fdc
/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
Packit 549fdc
   standard headers, defines conflicting implementations of _Alignas
Packit 549fdc
   and _Alignof that are no better than ours; override them.  */
Packit 549fdc
#undef _Alignas
Packit 549fdc
#undef _Alignof
Packit 549fdc
Packit 549fdc
/* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
Packit 549fdc
   <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.  */
Packit 549fdc
#if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
Packit 549fdc
     || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9)))
Packit 549fdc
# ifdef __cplusplus
Packit 549fdc
#  if 201103 <= __cplusplus
Packit 549fdc
#   define _Alignof(type) alignof (type)
Packit 549fdc
#  else
Packit 549fdc
   template <class __t> struct __alignof_helper { char __a; __t __b; };
Packit 549fdc
#   define _Alignof(type) offsetof (__alignof_helper<type>, __b)
Packit 549fdc
#  endif
Packit 549fdc
# else
Packit 549fdc
#  define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
Packit 549fdc
# endif
Packit 549fdc
#endif
Packit 549fdc
#if ! (defined __cplusplus && 201103 <= __cplusplus)
Packit 549fdc
# define alignof _Alignof
Packit 549fdc
#endif
Packit 549fdc
#define __alignof_is_defined 1
Packit 549fdc
Packit 549fdc
/* alignas (A), also known as _Alignas (A), aligns a variable or type
Packit 549fdc
   to the alignment A, where A is an integer constant expression.  For
Packit 549fdc
   example:
Packit 549fdc
Packit 549fdc
      int alignas (8) foo;
Packit 549fdc
      struct s { int a; int alignas (8) bar; };
Packit 549fdc
Packit 549fdc
   aligns the address of FOO and the offset of BAR to be multiples of 8.
Packit 549fdc
Packit 549fdc
   A should be a power of two that is at least the type's alignment
Packit 549fdc
   and at most the implementation's alignment limit.  This limit is
Packit 549fdc
   2**28 on typical GNUish hosts, and 2**13 on MSVC.  To be portable
Packit 549fdc
   to MSVC through at least version 10.0, A should be an integer
Packit 549fdc
   constant, as MSVC does not support expressions such as 1 << 3.
Packit 549fdc
   To be portable to Sun C 5.11, do not align auto variables to
Packit 549fdc
   anything stricter than their default alignment.
Packit 549fdc
Packit 549fdc
   The following C11 requirements are not supported here:
Packit 549fdc
Packit 549fdc
     - If A is zero, alignas has no effect.
Packit 549fdc
     - alignas can be used multiple times; the strictest one wins.
Packit 549fdc
     - alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
Packit 549fdc
Packit 549fdc
   */
Packit 549fdc
Packit 549fdc
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
Packit 549fdc
# if defined __cplusplus && 201103 <= __cplusplus
Packit 549fdc
#  define _Alignas(a) alignas (a)
Packit 549fdc
# elif ((defined __APPLE__ && defined __MACH__                  \
Packit 549fdc
         ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__)                 \
Packit 549fdc
         : __GNUC__)                                            \
Packit 549fdc
        || 061200 <= __HP_cc || 061200 <= __HP_aCC                \
Packit 549fdc
        || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__)
Packit 549fdc
#  define _Alignas(a) __attribute__ ((__aligned__ (a)))
Packit 549fdc
# elif 1300 <= _MSC_VER
Packit 549fdc
#  define _Alignas(a) __declspec (align (a))
Packit 549fdc
# endif
Packit 549fdc
#endif
Packit 549fdc
#if ((defined _Alignas && ! (defined __cplusplus && 201103 <= __cplusplus)) \
Packit 549fdc
     || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
Packit 549fdc
# define alignas _Alignas
Packit 549fdc
#endif
Packit 549fdc
#if defined alignas || (defined __cplusplus && 201103 <= __cplusplus)
Packit 549fdc
# define __alignas_is_defined 1
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
#endif /* _GL_STDALIGN_H */