alignof.h 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. /* Determine alignment of types.
  2. Copyright (C) 2003-2004, 2006, 2009 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. #ifndef _ALIGNOF_H
  15. #define _ALIGNOF_H
  16. #include <stddef.h>
  17. /* Determine the alignment of a type at compile time. */
  18. #if defined __GNUC__
  19. # define alignof __alignof__
  20. #elif defined __cplusplus
  21. template <class type> struct alignof_helper { char __slot1; type __slot2; };
  22. # define alignof(type) offsetof (alignof_helper<type>, __slot2)
  23. #else
  24. # define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
  25. #endif
  26. #endif /* _ALIGNOF_H */