| Deutsch English Français Italiano |
|
<vstjlk$mis5$2@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!eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: do { quit; } else { }
Date: Sun, 6 Apr 2025 12:05:40 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <vstjlk$mis5$2@dont-email.me>
References: <vspbjh$8dvd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 06 Apr 2025 12:05:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c834e100dafac4982983aaf86b8c8fc3";
logging-data="740229"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eBRTImQ7zWWWHmjunTfAhYfAvjkd98qc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:auprBY7WdKHztRudet4+FqM4JiY=
Content-Language: en-GB
In-Reply-To: <vspbjh$8dvd$1@dont-email.me>
Bytes: 2443
On 04/04/2025 21:23, Thiago Adams wrote:
> What do you think of this control block?
>
> do
> {
> FILE f = fopen("file.txt", "r");
>
> if (f == NULL) quit; /*goes to else part*/
>
> /*success here*/
> for (int i =0; i < 10; i++){
> ...
> if (error) quit;
> }
>
> }
> else
> {
> /*some error*/
> }
>
This does not strike me as worth the effort as a control block. There
are always vast numbers of ways to make different kinds of control
blocks in a language - the trick is to pick enough to be able to write
code conveniently, and not so many that it is hard to learn the language
and understand the code.
Modern languages often have some kind of try/except structure, which is
what this looks like. But I don't think that is a good idea to try to
bolt onto a C compiler as an extension - it would give little benefit
and a lot of incompatibility. It is best done as a more fundamental
part of a language design. Without integration in the library, all you
have is syntactic sugar for a "goto" without even saving much typing.
Now, if you were to invent a do / undo control block, where the "undo"
statement not merely exits the control block but undoes the effect of
everything done so far inside the block, /then/ you would have something
new and exciting!