Back to index

nagios-plugins  1.4.16
alignof.h
Go to the documentation of this file.
00001 /* Determine alignment of types.
00002    Copyright (C) 2003-2004, 2006, 2009-2010 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 3, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00017 
00018 #ifndef _ALIGNOF_H
00019 #define _ALIGNOF_H
00020 
00021 #include <stddef.h>
00022 
00023 /* Determine the alignment of a structure slot (field) of a given type,
00024    at compile time.  Note that the result depends on the ABI.
00025    Note: The result cannot be used as a value for an 'enum' constant,
00026    due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
00027 #if defined __cplusplus
00028   template <class type> struct alignof_helper { char __slot1; type __slot2; };
00029 # define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
00030 #else
00031 # define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
00032 #endif
00033 
00034 /* Determine the good alignment of a object of the given type at compile time.
00035    Note that this is not necessarily the same as alignof_slot(type).
00036    For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
00037    - when -malign-double is not specified:  alignof_slot(double) = 4,
00038    - when -malign-double is specified:      alignof_slot(double) = 8.
00039    Note: The result cannot be used as a value for an 'enum' constant,
00040    due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
00041 #if defined __GNUC__
00042 # define alignof_type __alignof__
00043 #else
00044 # define alignof_type alignof_slot
00045 #endif
00046 
00047 /* alignof is an alias for alignof_slot semantics, since that's what most
00048    callers need.
00049    Note: The result cannot be used as a value for an 'enum' constant,
00050    due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
00051 #define alignof alignof_slot
00052 
00053 #endif /* _ALIGNOF_H */