1 /* Test of <stdalign.h>.
2 Copyright 2009-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c. */
28 typedef long double longdouble;
29 typedef struct { char a[1]; } struct1;
30 typedef struct { char a[2]; } struct2;
31 typedef struct { char a[3]; } struct3;
32 typedef struct { char a[4]; } struct4;
34 verify (__alignof_is_defined == 1);
36 # error "alignof is not a macro"
39 #if __alignas_is_defined
40 verify (__alignas_is_defined == 1);
42 # error "alignas is not a macro"
44 # define CHECK_ALIGNAS(type) \
45 type alignas (1 << 3) type##_alignas; \
46 type _Alignas (1 << 3) type##_Alignas;
48 # define CHECK_ALIGNAS(type)
52 typedef struct { char slot1; type slot2; } type##_helper; \
53 verify (alignof (type) == offsetof (type##_helper, slot2)); \
54 verify (_Alignof (type) == alignof (type)); \
55 const int type##_alignment = alignof (type); \