Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 07. Dec 2024, 14:04:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vj1h4i$335q1$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
User-Agent : Mozilla Thunderbird
On 07/12/2024 11:34, Janis Papanagnou wrote:
On 06.12.2024 02:20, Bart wrote:
I used to be puzzled by this too: 'while' can both start a while
statement, and it can delimit a do-while statement. How is that possible?
A keyword (like 'while') is just a lexical token that can be used in
different syntactical contexts.
Is it common to both start and end a statememt with the same keyword?
(Even with different semantics, if a
language designer thinks this is a good idea for his case.)
You may be less confused with using Pascal;
Now you are demonstrating my point about being treated like a beginner. And it is exasperating.
This is a point of language design. C's approach works - just. But it relies on some subtlety. 'while (cond)' both starts a statement, and can end a statement:
do while(cond) do ; while (cond);
The second 'while' here starts a nested while-loop inside a do-while loop. Not confusing? It is to me! I couldn't finish my example as I got lost (but as it happens, this is valid code, partly by luck).
Of course, if you put aside all other matters and concentrate on the minutiae of the syntax details, then it is all 'obvious'. I think it needs to be a lot more obvious.
while positive-case do ...
until negative-case do ...
do ... while positive-case
do ... until negative-case
(depending on language with this of similar syntax).
There's nothing wrong using the same keyword for the same type of
condition, rather it's good to have it defined that way.
The problem here is exactly the same: how do you tell whether the 'while' in 'do ... while' is ending this 'do'-loop, or starting a nested while-loop?
You don't think there is an element of ambiguity here?
Let's take my example again:
do while(cond) do ; while (cond);
And make a small tweak:
do ; while(cond) do ; while (cond);
It still compiles, it is still valid code. But now it does something utterly different. (One is two nested loops, the other is two consecutive loops - I think!)
OK, I get now that people just aren't that bothered about such matters.
Obviously they aren't language designers.