Deutsch English Français Italiano |
<vj1noc$34ogu$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: question about linker Date: Sat, 7 Dec 2024 14:57:17 +0000 Organization: A noiseless patient Spider Lines: 82 Message-ID: <vj1noc$34ogu$1@dont-email.me> References: <vi54e9$3ie0o$1@dont-email.me> <87plmfu2ub.fsf@nosuchdomain.example.com> <vi9jk4$gse4$1@dont-email.me> <vi9kng$gn4c$1@dont-email.me> <87frnbt9jn.fsf@nosuchdomain.example.com> <viaqh0$nm7q$1@dont-email.me> <877c8nt255.fsf@nosuchdomain.example.com> <viasv4$nm7q$2@dont-email.me> <vibr1l$vvjf$1@dont-email.me> <vic73f$1205f$1@dont-email.me> <20241129142810.00007920@yahoo.com> <vicfra$13nl4$1@dont-email.me> <20241129161517.000010b8@yahoo.com> <vicque$15ium$2@dont-email.me> <vid110$16hte$1@dont-email.me> <vifcll$1q9rj$1@dont-email.me> <vifiib$1s07p$1@dont-email.me> <87ldwx10gv.fsf@bsb.me.uk> <vimtt4$27vv$1@dont-email.me> <86ser1kgp5.fsf@linuxsc.com> <vit69t$1qfgg$1@dont-email.me> <87ldwtzlc0.fsf@nosuchdomain.example.com> <vitjgg$1tukq$2@dont-email.me> <vj1bss$325uo$1@dont-email.me> <vj1h4i$335q1$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 07 Dec 2024 15:57:16 +0100 (CET) Injection-Info: dont-email.me; posting-host="92f4e16e4a21192eb5e2d0ba1a6ec304"; logging-data="3301918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hsvcOpQmKbZaD5/uMf+v2" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ML7eOxAyB8tfxc0cqK59nKetUkU= Content-Language: en-GB In-Reply-To: <vj1h4i$335q1$2@dont-email.me> Bytes: 4706 On 07/12/2024 13:04, Bart wrote: > 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!) Correction: the versions I tested don't have that 'do' in the middle. The two examples need to be written like this to be valid: do while (cond) ; while (cond); do ; while (cond) ; while (cond); So this /is/ two nested loops followed by two consecutive ones. The difference is that semicolon. In a syntax where newlines may be injecting semicolons, such a subtle distinction is not strong enough. As I originally said, it's fragile. Those suggesting that semicolons are unimportant details of syntax in C are wrong. They can make a significant difference and contribute to errors: for (i=0; i<n; ++i); printf("%d\n", i);