Date: Tue, 28 Jan 2025 23:38:12 +0100
wt., 7 sty 2025 o 02:55 Ville Voutilainen via Std-Proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> On Tue, 7 Jan 2025 at 03:35, Hyman Rosen via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Attaching labels to do/for/while/switch statements and having gotos target them is already legal in C and C++. If someone needs that construct, they can already use it whether the would-be masters of C++ style like it or not. So the argument against using those labels for break/continue seems to be that programmers would not normally write such gotos, but once they attach the labels, the temptation will be so overwhelming that they won't be able to help themselves. Which ... I can't even.
>
> That's not the argument. The argument is that if you happen to have
> gotos in your code, and I happen to have labeled loops in the same
> code, I don't
> have to consider my labeled loops as possible targets of your
> spaghetti jumps, because they can't be. I don't need to include them
> in my search for
> the possible targets of your spaghetti jumps.
What if `goto` labels could be marked as more "local"?
This fix both problems at once, with `goto` to make it more "structured"
and allow duplicate names for `for` in one function.
```
{
local_label*: // character `*` make label only visible in scope
int i = 0;
goto local_label; //allowed
}
//goto local_label; //error
{
local_label*: for(int i = 0; i < 10; ++i) break local_label;
//local_label*: while(true) break local_label; //this is error as we
have already same label in same scope
{
local_label*: while(true) goto local_label; //this is fine, it
shadow outer scope label
}
}
```
This makes it near impossible to make spaghetti jumps as you need only consider
things in local `{}`.
Would this solve your concerns or is this not enough?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> On Tue, 7 Jan 2025 at 03:35, Hyman Rosen via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Attaching labels to do/for/while/switch statements and having gotos target them is already legal in C and C++. If someone needs that construct, they can already use it whether the would-be masters of C++ style like it or not. So the argument against using those labels for break/continue seems to be that programmers would not normally write such gotos, but once they attach the labels, the temptation will be so overwhelming that they won't be able to help themselves. Which ... I can't even.
>
> That's not the argument. The argument is that if you happen to have
> gotos in your code, and I happen to have labeled loops in the same
> code, I don't
> have to consider my labeled loops as possible targets of your
> spaghetti jumps, because they can't be. I don't need to include them
> in my search for
> the possible targets of your spaghetti jumps.
What if `goto` labels could be marked as more "local"?
This fix both problems at once, with `goto` to make it more "structured"
and allow duplicate names for `for` in one function.
```
{
local_label*: // character `*` make label only visible in scope
int i = 0;
goto local_label; //allowed
}
//goto local_label; //error
{
local_label*: for(int i = 0; i < 10; ++i) break local_label;
//local_label*: while(true) break local_label; //this is error as we
have already same label in same scope
{
local_label*: while(true) goto local_label; //this is fine, it
shadow outer scope label
}
}
```
This makes it near impossible to make spaghetti jumps as you need only consider
things in local `{}`.
Would this solve your concerns or is this not enough?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-01-28 22:38:46