maint: update all copyright year number ranges
[gnulib.git] / lib / alignof.h
1 /* Determine alignment of types.
2    Copyright (C) 2003-2004, 2006, 2009-2012 Free Software Foundation, Inc.
3
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)
7    any later version.
8
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.
13
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.  */
17
18 #ifndef _ALIGNOF_H
19 #define _ALIGNOF_H
20
21 #include <stddef.h>
22
23 /* alignof_slot (TYPE)
24    Determine the alignment of a structure slot (field) of a given type,
25    at compile time.  Note that the result depends on the ABI.
26    This is the same as alignof (TYPE) and _Alignof (TYPE), defined in
27    <stdalign.h> if __alignof_is_defined is 1.
28    Note: The result cannot be used as a value for an 'enum' constant,
29    due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
30 #if defined __cplusplus
31   template <class type> struct alignof_helper { char __slot1; type __slot2; };
32 # define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
33 #else
34 # define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
35 #endif
36
37 /* alignof_type (TYPE)
38    Determine the good alignment of an object of the given type at compile time.
39    Note that this is not necessarily the same as alignof_slot(type).
40    For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
41    - when -malign-double is not specified:  alignof_slot(double) = 4,
42    - when -malign-double is specified:      alignof_slot(double) = 8.
43    Note: The result cannot be used as a value for an 'enum' constant,
44    due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
45 #if defined __GNUC__
46 # define alignof_type __alignof__
47 #else
48 # define alignof_type alignof_slot
49 #endif
50
51 #endif /* _ALIGNOF_H */