Sujet : Re: Top 10 most common hard skills listed on resumes...
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 30. Aug 2024, 21:41:50
Autres entêtes
Organisation : None to speak of
Message-ID : <871q2568vl.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
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.
However, the compilers I've tried produce the same diagnostic (not a
syntax error message) for both. Probably they use a tweaked grammar
that allows more a general expression as the LHS of an assignment,
and catch errors later in semantic analysis, for the purpose of
producing diagnostics that are easier to understand. It's obvious
that in `x + 1 = y`, the programmer (probably) intended `x + 1`
to be the LHS of an assignment. These compilers (I tried gcc,
clang, and tcc) are clever enough to recognize that.
For most programmers (in my opinion and apparently in the opinions
of those compiler developers), the fact that the two intended
assignments are invalid for different technical reasons is less
important than understanding that they're invalid, and in a way
that helps the programmer figure out how to correct them.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */