Deutsch English Français Italiano |
<vjhcvb$3e9an$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!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: goto considered helpful Date: Fri, 13 Dec 2024 14:31:23 +0100 Organization: A noiseless patient Spider Lines: 68 Message-ID: <vjhcvb$3e9an$2@dont-email.me> References: <vi54e9$3ie0o$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> <vj1mhi$34p7h$1@dont-email.me> <vj1prj$35je4$1@dont-email.me> <vj7dup$he7i$1@dont-email.me> <vjasuj$17uod$1@dont-email.me> <vjc87h$1apid$1@paganini.bofh.team> <vjcbe1$1jns0$1@dont-email.me> <87wmg5x4b1.fsf@nosuchdomain.example.com> <vjd96b$1pbed$1@dont-email.me> <87jzc5wx3s.fsf@nosuchdomain.example.com> <vjdde8$1q2to$2@dont-email.me> <87frmtwuzq.fsf@nosuchdomain.example.com> <20241212144454.00003b83@yahoo.com> <87wmg4vaeb.fsf@nosuchdomain.example.com> <vjgsfq$3ajis$1@dont-email.me> <vjh4qc$3c7nb$1@dont-email.me> <20241213143911.00004af2@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 13 Dec 2024 14:31:24 +0100 (CET) Injection-Info: dont-email.me; posting-host="f0540cf273b21a8c1d582ae5f5d2a6e9"; logging-data="3614039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MpF3NjW3taG4X+zOIIzpa8re6DVOEozY=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:8EJ5KIDd/GWR711b4VNm9uUCjqg= In-Reply-To: <20241213143911.00004af2@yahoo.com> Content-Language: en-GB Bytes: 4469 On 13/12/2024 13:39, Michael S wrote: > On Fri, 13 Dec 2024 11:12:13 +0000 > bart <bc@freeuk.com> wrote: > >> >> >> Some people don't like ordinary break either. There you could also >> suggest using convoluted logic, or using a function instead But here >> 'break' would be clearly be simpler and easier. >> > > Agreed. > >> (I'd like to see a lambda example that is simpler than a two-level >> break or even a goto.) >> > > It would not be simpler than goto, but a little easier to follow. > Relatively to two-level break, it's more general. Suppose, you have 3 > levels of nested loops. Two-level break does not help for breaking > out of innermost loop *into* outermost loop. > > The problem with lambda in this role is that it would be an overkill. Some might say "overkill" - others would say that if C first gains a powerful feature that can be useful in many contexts, then multi-level break is unnecessary. I would not imagine adding lambdas to the language /solely/ for this use-case! > Also if one wants simplicity of writing then David's suggestion for > lambda without capture is not sufficient. On the other hand, lambda > with capture of full environment by reference is very easy to write, > but potentially very hard to follow and error-prone. > I did not suggest lambdas without captures - I suggested lambdas with the restriction that closure objects would not be needed. In particular, as long as the lambda is only ever used within the lifetime of any variables it captures by reference, no closure object is ever needed. If a function is returning a lambda or passing it on somewhere, then I would think it would be appropriate for C to restrict the lambda to one without captures. In C++, such lambdas can be converted to function pointers of appropriate, and the same ought to apply in C. (constexpr data in scope at the definition of the lambda can be freely used as though they are implicit captures.) (In C++ programming, I am not keen on lambdas catching by default, whether [=] or [&]. I prefer explicit capture lists.) > I am strictly inclined to think that goto is better than all > alternatives proposed so far. > >> I've had a quick look through my codebases (not C), and I couldn't >> see an example of a numbered break. All I could find was the >> equivalant of: >> >> break # the vast majority >> break all >> >> The latter breaks out of the outermost loop. >> > > For the reason explained above I don't like 'break all' idea. > > >