Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #167329
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Newsgroups | comp.lang.c, comp.lang.fortran, comp.lang.c++ |
| Subject | Re: labels at the end of a function |
| Date | 2022-08-30 11:20 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <tekrpn$70v$1@gioia.aioe.org> (permalink) |
| References | <tejphm$19h6e$1@dont-email.me> <cone.1661827324.810372.52241.1004@monster.email-scan.com> <20220830124652.bab3908329ccf4b6cf52d33d@g{oogle}mail.com> |
Cross-posted to 3 groups.
In comp.lang.c++ Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
>> The more goto-s get written, the more likely is it for
>> Chulhu to appear and bring humanity to an end.
>
> I disagree. Structured use of GOTO's (the topic of a Knuch
> article!), especially when they jump down and nest stack-
> like can greately simplify certain code structures. They
> help to avoid returns from mid-function, and let the
> programmer execute common deinitialisation code.
That may be true in C, but C++ throws a spanner in the works because
of one fun feature: Exceptions.
If running the deinitialization code is crucial (or else for example
resources will be leaked, such as file handles left open), it won't
be run no matter how many gotos you use if anything along the line
throws an exception and it's not caught.
This is one of the main reasons to use RAII instead of gotos: Object
destructors will always be run no matter how the function is exited,
be it an early return, be it an exception.
As a bonus, if you implement it properly, the code will actually become
cleaner.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
labels at the end of a function Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-29 20:35 -0500
Re: labels at the end of a function Thiago Adams <thiago.adams@gmail.com> - 2022-08-29 18:47 -0700
Re: labels at the end of a function Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-29 21:50 -0700
Re: labels at the end of a function Kaz Kylheku <480-992-1380@kylheku.com> - 2022-08-30 05:52 +0000
Re: labels at the end of a function Sam <sam@email-scan.com> - 2022-08-29 22:42 -0400
Re: labels at the end of a function Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-30 12:46 +0300
Re: labels at the end of a function Juha Nieminen <nospam@thanks.invalid> - 2022-08-30 11:20 +0000
Re: labels at the end of a function Opus <ifonly@youknew.org> - 2022-08-30 20:15 +0200
Re: labels at the end of a function Ike Naar <ike@sdf.org> - 2022-08-30 05:50 +0000
Re: labels at the end of a function Elephant <diespammer@yahoo.it> - 2022-08-30 10:14 +0200
Re: labels at the end of a function Bo Persson <bo@bo-persson.se> - 2022-08-30 09:14 +0200
Re: labels at the end of a function scott@slp53.sl.home (Scott Lurndal) - 2022-08-30 13:21 +0000
Re: labels at the end of a function gazelle@shell.xmission.com (Kenny McCormack) - 2022-08-30 14:44 +0000
Re: labels at the end of a function Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-30 16:08 -0500
Re: labels at the end of a function Anton Shepelev <anton.txt@gmail.com> - 2022-08-31 01:04 +0300
Re: labels at the end of a function Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-30 20:29 -0500
csiph-web