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 3, or (at your option)
7 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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 #ifndef _ALIGNOF_H
19 #define _ALIGNOF_H
21 #include <stddef.h>
23 /* Determine the alignment of a type at compile time. */
24 #if defined __GNUC__
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)
29 #else
30 # define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
31 #endif
33 #endif /* _ALIGNOF_H */