X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstdalign.in.h;h=1523058134018d6b3296a603c5da3e63c0183689;hb=341111f654709cd0295607a4abbe721495c77e90;hp=092dfedae6606124d7cfd571fe029fb92de4708c;hpb=6dc2ffa573d23caeeb62c4ba3b9a630a1261e35d;p=gnulib.git diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h index 092dfedae..152305813 100644 --- a/lib/stdalign.in.h +++ b/lib/stdalign.in.h @@ -1,6 +1,6 @@ -/* A substitute for ISO C 1x . +/* A substitute for ISO C11 . - Copyright 2011 Free Software Foundation, Inc. + Copyright 2011-2012 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -13,30 +13,35 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program; if not, see . */ /* Written by Paul Eggert and Bruno Haible. */ #ifndef _GL_STDALIGN_H #define _GL_STDALIGN_H -/* ISO C1X for platforms that lack it. +/* ISO C11 for platforms that lack it. References: - ISO C1X + ISO C11 (latest free draft + ) sections 6.5.3.4, 6.7.5, 7.15. - C++0X + C++11 (latest free draft + ) section 18.10. */ -/* Return the alignment of a structure slot (field) of TYPE, - as an integer constant expression. The result cannot be used as a - value for an 'enum' constant, if you want to be portable to HP-UX - 10.20 cc and AIX 3.2.5 xlc. +/* alignof (TYPE), also known as _Alignof (TYPE), yields the alignment + requirement of a structure member (i.e., slot or field) that is of + type TYPE, as an integer constant expression. - This is not the same as GCC's __alignof__ operator; for example, on - x86 with GCC, _Alignof (long long) is typically 4 whereas - __alignof__ (long long) is 8. */ + This differs from GCC's __alignof__ operator, which can yield a + better-performing alignment for an object of that type. For + example, on x86 with GCC, __alignof__ (double) and __alignof__ + (long long) are 8, whereas alignof (double) and alignof (long long) + are 4 unless the option '-malign-double' is used. + + The result cannot be used as a value for an 'enum' constant, if you + want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */ #include #if defined __cplusplus template struct __alignof_helper { char __a; __t __b; }; @@ -47,11 +52,35 @@ #define alignof _Alignof #define __alignof_is_defined 1 -/* Align a type or variable to the alignment A. */ -#if @HAVE_ATTRIBUTE_ALIGNED@ && !defined __cplusplus +/* alignas (A), also known as _Alignas (A), aligns a variable or type + to the alignment A, where A is an integer constant expression. For + example: + + int alignas (8) foo; + struct s { int a; int alignas (8) bar; }; + + aligns the address of FOO and the offset of BAR to be multiples of 8. + + A should be a power of two that is at least the type's alignment + and at most the implementation's alignment limit. This limit is + 2**28 on typical GNUish hosts, and 2**13 on MSVC. To be portable + to MSVC through at least version 10.0, A should be an integer + constant, as MSVC does not support expressions such as 1 << 3. + To be portable to Sun C 5.11, do not align auto variables to + anything stricter than their default alignment. + + The following C11 requirements are not supported here: + + - If A is zero, alignas has no effect. + - alignas can be used multiple times; the strictest one wins. + - alignas (TYPE) is equivalent to alignas (alignof (TYPE)). + + */ + +#if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C # define _Alignas(a) __attribute__ ((__aligned__ (a))) #elif 1300 <= _MSC_VER -# define _Alignas(a) __declspec ((align (a))) +# define _Alignas(a) __declspec (align (a)) #endif #ifdef _Alignas # define alignas _Alignas