7256ede92ebe608ec599fa290fc68bb8a4e2c400
[debian/tar] / gnu / stdalign.in.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* A substitute for ISO C11 <stdalign.h>.
4
5    Copyright 2011-2013 Free Software Foundation, Inc.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
19
20 /* Written by Paul Eggert and Bruno Haible.  */
21
22 #ifndef _GL_STDALIGN_H
23 #define _GL_STDALIGN_H
24
25 /* ISO C11 <stdalign.h> for platforms that lack it.
26
27    References:
28    ISO C11 (latest free draft
29    <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>)
30    sections 6.5.3.4, 6.7.5, 7.15.
31    C++11 (latest free draft
32    <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>)
33    section 18.10. */
34
35 /* alignof (TYPE), also known as _Alignof (TYPE), yields the alignment
36    requirement of a structure member (i.e., slot or field) that is of
37    type TYPE, as an integer constant expression.
38
39    This differs from GCC's __alignof__ operator, which can yield a
40    better-performing alignment for an object of that type.  For
41    example, on x86 with GCC, __alignof__ (double) and __alignof__
42    (long long) are 8, whereas alignof (double) and alignof (long long)
43    are 4 unless the option '-malign-double' is used.
44
45    The result cannot be used as a value for an 'enum' constant, if you
46    want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
47 #include <stddef.h>
48 #if defined __cplusplus
49    template <class __t> struct __alignof_helper { char __a; __t __b; };
50 # define _Alignof(type) offsetof (__alignof_helper<type>, __b)
51 #else
52 # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
53 #endif
54 #define alignof _Alignof
55 #define __alignof_is_defined 1
56
57 /* alignas (A), also known as _Alignas (A), aligns a variable or type
58    to the alignment A, where A is an integer constant expression.  For
59    example:
60
61       int alignas (8) foo;
62       struct s { int a; int alignas (8) bar; };
63
64    aligns the address of FOO and the offset of BAR to be multiples of 8.
65
66    A should be a power of two that is at least the type's alignment
67    and at most the implementation's alignment limit.  This limit is
68    2**28 on typical GNUish hosts, and 2**13 on MSVC.  To be portable
69    to MSVC through at least version 10.0, A should be an integer
70    constant, as MSVC does not support expressions such as 1 << 3.
71    To be portable to Sun C 5.11, do not align auto variables to
72    anything stricter than their default alignment.
73
74    The following C11 requirements are not supported here:
75
76      - If A is zero, alignas has no effect.
77      - alignas can be used multiple times; the strictest one wins.
78      - alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
79
80    */
81
82 #if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C
83 # define _Alignas(a) __attribute__ ((__aligned__ (a)))
84 #elif 1300 <= _MSC_VER
85 # define _Alignas(a) __declspec (align (a))
86 #endif
87 #ifdef _Alignas
88 # define alignas _Alignas
89 # define __alignas_is_defined 1
90 #endif
91
92 #endif /* _GL_STDALIGN_H */