Liste des Groupes | Revenir à l c |
On Mon 5/5/2025 1:43 PM, Keith Thompson wrote:What C90 constraint does it violate? Both gcc and clang reject it>
with "-std=c90 -pedantic-errors", with an error message "ISO C90
forbids subscripting non-lvalue array", but I don't see a relevant
constraint in the C90 standard.
The "constraint" in C89/90 is simply the fact that C89/90 _requires_
an lvalue (of array type) in order to apply array to pointer
conversion. Here's is the original wording:
>
Except when it is the operand of the sizeof operator or the unary &
operator, or is a character string literal used to initialize an
array of character type, or is a wide string literal used to
initialize an array with element type compatible with wchar-t, an
*lvalue* that has type “array of type” is converted to an expression
that has type “pointer to rype” that points to the initial element
of the array object and is not an lvalue.
>
The presence of that "*lvalue*" requirement is what prevented up from
using `[]` operator on non-lvalue arrays in C89/90, because `[]`
critically relies on that conversion.
>
In C11 the wording has changed:
>
Except when it is the operand of the sizeof operator, the _Alignof
operator, or the unary & operator, or is a string literal used to
initialize an array, an expression that has type ‘‘array of type’’
is converted to an expression with type ‘‘pointer to type’’ that
points to the initial element of the array object and is not an
lvalue. If the array object has register storage class, the behavior
is undefined.
>
Note that the "lvalue" requirement has disappeared from this
wording. That is exactly why since C99 we can apply `[]` to non-lvalue
arrays.
Les messages affichés proviennent d'usenet.