Blame gettext-tools/gnulib-lib/alignof.h

Packit Bot 06c835
/* Determine alignment of types.
Packit Bot 06c835
   Copyright (C) 2003-2004, 2006, 2009-2015 Free Software Foundation, Inc.
Packit Bot 06c835
Packit Bot 06c835
   This program is free software; you can redistribute it and/or modify
Packit Bot 06c835
   it under the terms of the GNU General Public License as published by
Packit Bot 06c835
   the Free Software Foundation; either version 3, or (at your option)
Packit Bot 06c835
   any later version.
Packit Bot 06c835
Packit Bot 06c835
   This program is distributed in the hope that it will be useful,
Packit Bot 06c835
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Bot 06c835
   GNU General Public License for more details.
Packit Bot 06c835
Packit Bot 06c835
   You should have received a copy of the GNU General Public License
Packit Bot 06c835
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit Bot 06c835
Packit Bot 06c835
#ifndef _ALIGNOF_H
Packit Bot 06c835
#define _ALIGNOF_H
Packit Bot 06c835
Packit Bot 06c835
#include <stddef.h>
Packit Bot 06c835
Packit Bot 06c835
/* alignof_slot (TYPE)
Packit Bot 06c835
   Determine the alignment of a structure slot (field) of a given type,
Packit Bot 06c835
   at compile time.  Note that the result depends on the ABI.
Packit Bot 06c835
   This is the same as alignof (TYPE) and _Alignof (TYPE), defined in
Packit Bot 06c835
   <stdalign.h> if __alignof_is_defined is 1.
Packit Bot 06c835
   Note: The result cannot be used as a value for an 'enum' constant,
Packit Bot 06c835
   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
Packit Bot 06c835
#if defined __cplusplus
Packit Bot 06c835
  template <class type> struct alignof_helper { char __slot1; type __slot2; };
Packit Bot 06c835
# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
Packit Bot 06c835
#else
Packit Bot 06c835
# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
/* alignof_type (TYPE)
Packit Bot 06c835
   Determine the good alignment of an object of the given type at compile time.
Packit Bot 06c835
   Note that this is not necessarily the same as alignof_slot(type).
Packit Bot 06c835
   For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
Packit Bot 06c835
   - when -malign-double is not specified:  alignof_slot(double) = 4,
Packit Bot 06c835
   - when -malign-double is specified:      alignof_slot(double) = 8.
Packit Bot 06c835
   Note: The result cannot be used as a value for an 'enum' constant,
Packit Bot 06c835
   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
Packit Bot 06c835
#if defined __GNUC__ || defined __IBM__ALIGNOF__
Packit Bot 06c835
# define alignof_type __alignof__
Packit Bot 06c835
#else
Packit Bot 06c835
# define alignof_type alignof_slot
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
#endif /* _ALIGNOF_H */