1 /* A substitute for ISO C 1x <stdalign.h>.
3 Copyright 2011 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Paul Eggert and Bruno Haible. */
21 #ifndef _GL_STDALIGN_H
22 #define _GL_STDALIGN_H
24 /* ISO C1X <stdalign.h> for platforms that lack it.
27 ISO C1X <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>
28 sections 6.5.3.4, 6.7.5, 7.15.
29 C++0X <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>
32 /* Return the alignment of a structure slot (field) of TYPE,
33 as an integer constant expression. The result cannot be used as a
34 value for an 'enum' constant, if you want to be portable to HP-UX
35 10.20 cc and AIX 3.2.5 xlc.
37 This is not the same as GCC's __alignof__ operator; for example, on
38 x86 with GCC, _Alignof (long long) is typically 4 whereas
39 __alignof__ (long long) is 8. */
41 #if defined __cplusplus
42 template <class __t> struct __alignof_helper { char __a; __t __b; };
43 # define _Alignof(type) offsetof (__alignof_helper<type>, __b)
45 # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
47 #define alignof _Alignof
48 #define __alignof_is_defined 1
50 /* Align a type or variable to the alignment A. */
51 #if @HAVE_ATTRIBUTE_ALIGNED@ && !defined __cplusplus
52 # define _Alignas(a) __attribute__ ((__aligned__ (a)))
53 #elif 1300 <= _MSC_VER
54 # define _Alignas(a) __declspec ((align (a)))
57 # define alignas _Alignas
58 # define __alignas_is_defined 1
61 #endif /* _GL_STDALIGN_H */