Initializer Lists in Operator Arguments
The use of initializer lists on the right-hand side (RHS) of operators, a feature absent in C 11, raises questions about the reasoning behind this restriction.
The C standard prohibits the direct use of initializer lists on the RHS of binary operators like ' ', '*', or '<<'. This stems from the fact that initializer lists are not considered expressions according to §5 of the Standard, which prohibits their use in functions and binary operator arguments.
To facilitate the use of initializer lists, the standard introduces exceptions. However, there is no such exception for binary operators, leaving initializer lists restricted on both sides.
The decision behind this restriction is explained in N2215 by Stroustrup and Dos Reis (2007). Allowing initializer lists as the left-hand operand would lead to parsing conflicts due to the use of curly braces for both initializer lists and blocks.
Furthermore, permitting initializer lists only on the RHS as opposed to both sides was deemed to create an excessive inconsistency. Hence, initializer lists are allowed in certain contexts, such as function arguments, subscripts, and assignments, but not in the general case of binary operator arguments.
The above is the detailed content of Why Are Initializer Lists Restricted in C Binary Operator Arguments?. For more information, please follow other related articles on the PHP Chinese website!