Blame lib/alignof.h

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