Liste des Groupes | Revenir à cl c |
On 30/08/2024 21:41, Keith Thompson wrote:
>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:>
>Kaz Kylheku <643-408-1753@kylheku.com> writes:>
>On 2024-08-29, Ben Bacarisse <ben@bsb.me.uk> wrote:>
>Bart <bc@freeuk.com> writes:>
>I think that these (with x, y having compatible scalar types):>
>
x + 1 = y;
(x + 1) = y; // in case above was parsed differently
>
are both valid syntax in C. It will fail for a different reason:
an '+' term is not a valid lvalue.
The compiler must tell you that neither is valid C. That's
because what is required on each side of assignment is not
exactly the same thing. It's a distraction to argue about why
each is not valid C as both have errors that require diagnostic
at compile time.
Bart is only saying that it's valid syntax, not that it's valid C.
>
According to the ISO C syntax (not taking into account contraints,
which are not syntax) that view is justified.
The second line is syntactically well-formed. The first line is
not.
Right, because the LHS of an assignment is a unary-expression.
`(x + 1)` can be parsed as a unary-expression, but `x + 1` cannot.
AFAICT both terms are parsed the same way.
>
Given this:
>
x + y = z;
(x + y) = z;
>
My compiler produces the same AST for the LHS of '=' in both
cases.
Les messages affichés proviennent d'usenet.