C++ Logo

std-proposals

Advanced search

[std-proposals] goto is not harmful (was: "once" keyword)

From: Alejandro Colomar <alx.manpages_at_[hidden]>
Date: Wed, 24 May 2023 15:02:56 +0200
On 5/24/23 14:57, LUCE Jean-Sébastien via Std-Proposals wrote:
> Hello
>
> It is often useful to support multiple cancel conditions, like 'return' in
> a function, but without having to isolate the code in such a function
> (which is called from a single point).
>
> I'm used to write code like
>
> "
> do {
> if (Failed(Condition0))
> break;
> if (Failed(Condition1))
> break;
> Code_to_execute;
> } while (0);
> "

The keyword exists, with a lovely name: goto

```c
    if (failed(foo))
        goto x;
    if (failed(bar))
        goto x;

    baz();
x:
```



[...]

>
> The syntaxe is still "hacked" someway, since "continue" could be used
> wrongly, or final "break" may be forgotten.

Oh, this would be funny. I'd love to see a continue in a while(0), just
for fun. I'd be in a bridge, between killing the offender, and ROFL. :D

>
> I would like "once" behave like do { } while(0);, where only "break" (and
> not "continue") would have a meaning.
>
> for example above could be converted as
> "
> once {
> if (Failed(Condition0))
> break;
> if (Failed(Condition1))
> break;
> Code_to_execute;
> }
> "
>
> "
> once (Condition0) {
> if (Failed(Condition1))
> break;
> Code_to_execute;
> }
> "
>
> "once" could be followed or not by a first condition.
>
> Thanks
>
>

Received on 2023-05-24 13:02:59