Sujet : Re: Top 10 most common hard skills listed on resumes...
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 30. Aug 2024, 14:40:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86h6b2w2m9.fsf@linuxsc.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.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Kaz Kylheku <
643-408-1753@kylheku.com> writes:
On 2024-08-29, Ben Bacarisse <ben@bsb.me.uk> wrote:
[.. is assignment in C symmetric w.r.t. the two sides of '=' ..]
Have you taken Bart's bait and are now discussing a narrower
context?
>
The claim that C's assignment is symmetric and what is required on
the two sides is exactly the same is junk. C's assignment has
different syntax on each side, and what is required is even more
strict.
>
In the ISO C grammar for assignment, there is a "unary expression"
on the left and an "assignment expression" on the right. That's
just a particular factoring of the grammar that implementors don't
have to follow, if the correct results are produced.
>
Under a parser generator tool we could have a production rule like
expr '=' expr , where the '=' token has an elsewhere-declared
associativity and precedence.
>
The basic idea that the same syntactic kind of thing is on both
sides of a C assignment (with an additional lvalue constraint) is
valid; it's just not literally true if we are discussing the
details of how ISO C expresses the grammar.
I think this kind of reasoning is more harmful than helpful. The
point of the discussion is to understand what the ISO C standard
requires. Constraints apply only in the context of a complete
parse of a syntactically well-formed translation unit. To give
an example:
enum { A = 47 };
int
foo( int x ){
int A = 23;
return x+A;
}
There is nothing wrong with this translation unit. But if we
look at just the 'A = 23' as an assignment expression, it
violates a constraint. Reasoning about how an implementation
might go about parsing its input might lead one astray as to
how compilers are allowed to behave.
Of course implementations are allowed to phrase diagnostics in
any way they choose, even when a diagnostic is required. But for
understanding what the C standard mandates, it's better not to
think about how the parsing might be done, and instead follow the
given easy-to-understand guideline, namely, that constraints
apply only in the context of a complete parse of a syntactically
well-formed translation unit. If a translation unit is not
syntactically well-formed then no further consideration is needed
because it already doesn't comply with the C standard's rules;
it's only when a translation unit is completely syntactically
well-formed that one needs to think about constraint violations
and whether constraints are violated.