Blame gl/stdalign.in.h

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