I was interested in the following: is this new alignment _Alignas
specifier in C11 applicable to structure elements?
I've always thought so much, but a full reading of the N1570 public project seems to indicate that the alignment specifier cannot appear on the list of qualifier specifiers that I expect to be if it were supported. I read the grammar a couple of times, but I can’t understand how _Alignasit is supposed to be allowed in a member declaration.
However, it seems to me that the purpose of the standard is that it
_Alignasshould be applicable to members of the structure as a paragraph on _Alignas(§ 6.7.5) it says that "the alignment attribute should not be specified in the declaration of a [...] bit field". Given this term “bit field” is defined in § 6.7.2.1 as a member structure (exact wording: “such a member is called a bit field”), I have always interpreted this sentence to implicitly mean alignment specifiers were allowed for members other than the bit field .
A check of existing implementations shows that Clang 3.0 and GCC 4.7 support _Alignason structural elements without complaining (with help -pedantic). Clang source code reproduces the same grammar from N1570, except for Parser::ParseSpecifierQualifierList
allowing alignment specification; the function does contain a TODO element, though, it says:
/// TODO: diagnose attribute-specifiers and alignment-specifiers.
The GCC C parser code looks similar, i.e. even if it quotes a standard grammar, it allows alignment specifiers in lists of qualifier-classifiers.
I also checked the list of known defects, as well as comp.lang.c and comp.std.c, to see if this topic was raised, but it seems to be wrong. Therefore, my question is: alignment specifiers should be allowed to members of the structure?
EDIT: Relevant grammar rules:
(6.7) declaration-specifiers:
storage-class-specifier declaration-specifiers_opt
type-specifier declaration-specifiers_opt
type-qualifier declaration-specifiers_opt
function-specifier declaration-specifiers_opt
alignment-specifier declaration-specifiers_opt
(6.7.2.1) struct-or-union-specifier:
struct-or-union identifier_opt { struct-declaration-list }
struct-or-union identifier
(6.7.2.1) struct-declaration-list:
struct-declaration
struct-declaration-list struct-declaration
(6.7.2.1) struct-declaration:
specifier-qualifier-list struct-declarator-list_opt ;
static_assert-declaration
(6.7.2.1) specifier-qualifier-list:
type-specifier specifier-qualifier-list_opt
type-qualifier specifier-qualifier-list_opt
(6.7.5) alignment-specifier:
_Alignas ( type-name )
_Alignas ( constant-expression )
source
share