1 /* Determine alignment of types.
2 Copyright (C) 2003-2004, 2006, 2009 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 2, or (at your option)
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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 /* Determine the alignment of a type at compile time. */
25 # define alignof __alignof__
26 #elif defined __cplusplus
27 template <class type> struct alignof_helper { char __slot1; type __slot2; };
28 # define alignof(type) offsetof (alignof_helper<type>, __slot2)
30 /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
32 # define alignof(type) (sizeof (type) <= 4 ? 4 : 8)
34 /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
36 # define alignof(type) (sizeof (type) <= 4 ? 4 : 8)
38 # define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
41 #endif /* _ALIGNOF_H */