Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Redundant return() |
| Date | 2012-05-16 10:24 +1200 |
| Message-ID | <a1g3dgFd96U7@mid.individual.net> (permalink) |
| References | (2 earlier) <jorci2$5pa$1@speranza.aioe.org> <27375124.1151.1337067212163.JavaMail.geo-discussion-forums@vbip22> <return-20120515095002@ram.dialup.fu-berlin.de> <jotj8p$2j5$1@dont-email.me> <joujll$pv1$1@dont-email.me> |
On 05/16/12 09:58 AM, BartC wrote: > "James Kuyper"<jameskuyper@verizon.net> wrote in message > news:jotj8p$2j5$1@dont-email.me... >> On 05/15/2012 03:51 AM, Stefan Ram wrote: > > >>> is that tests have shown that this often executes faster >>> than a single exit. >> >> Any decent modern compiler should generate the same code either way, so >> if it does run noticeably faster using one approach, then you should get >> a better compiler. >> >> The relevant issue isn't speed, but ease of comprehension. Supporters of >> "single exit" claim it's easier to comprehend; my personal experience is >> that early-return is easier. > > Yes. Easier in that there is then a choice. > > I can't see the problem with multiple returns. No matter how many returns > there are in one function, the next statement executed will always be the > one falling the original call. That's not much different from 'single exit'. Clean-up is always the elephant in the room with multiple returns in C. Hence the proliferation of goto spaghetti. I for one prefer early return on precondition tests, but once a function allocates a resource or changes a state, there should only be one. Multiple returns are more common (and banning them unnecessary) in languages that have support for automatic clean-up. All safety (as in user) focused C coding standards I have seen specify a single return. -- Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Redundant return() pembed2012 <once@was.enough.invalid> - 2012-05-12 21:41 +0000
Re: Redundant return() pembed2012 <once@was.enough.invalid> - 2012-05-12 21:56 +0000
Re: Redundant return() Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-05-12 17:07 -0600
Re: Redundant return() James Kuyper <jameskuyper@verizon.net> - 2012-05-12 18:46 -0400
Re: Redundant return() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-05-12 20:10 -0400
Re: Redundant return() James Kuyper <jameskuyper@verizon.net> - 2012-05-12 21:29 -0400
Re: Redundant return() Barry Schwarz <schwarzb@dqel.com> - 2012-05-12 15:49 -0700
Re: Redundant return() pembed2012 <once@was.enough.invalid> - 2012-05-14 16:40 +0000
Re: Redundant return() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-14 17:57 +0100
Re: Redundant return() nick_keighley_nospam@hotmail.com - 2012-05-15 00:33 -0700
Re: Redundant return() nick_keighley_nospam@hotmail.com - 2012-05-15 03:03 -0700
Re: Redundant return() nick_keighley_nospam@hotmail.com - 2012-05-15 03:26 -0700
Re: Redundant return() James Kuyper <jameskuyper@verizon.net> - 2012-05-15 08:51 -0400
Re: Redundant return() "BartC" <bc@freeuk.com> - 2012-05-15 12:20 +0100
Re: Redundant return() Ian Collins <ian-news@hotmail.com> - 2012-05-16 07:59 +1200
Re: Redundant return() Kaz Kylheku <kaz@kylheku.com> - 2012-05-15 20:08 +0000
Re: Redundant return() Ian Collins <ian-news@hotmail.com> - 2012-05-16 08:18 +1200
Re: Redundant return() Lanarcam <lanarcam1@yahoo.fr> - 2012-05-15 22:48 +0200
Re: Redundant return() Ian Collins <ian-news@hotmail.com> - 2012-05-16 09:56 +1200
Re: Redundant return() "BartC" <bc@freeuk.com> - 2012-05-15 22:59 +0100
Re: Redundant return() Ian Collins <ian-news@hotmail.com> - 2012-05-16 10:16 +1200
Re: Redundant return() "BartC" <bc@freeuk.com> - 2012-05-16 09:29 +0100
Re: Redundant return() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-05-15 07:51 -0400
Re: Redundant return() James Kuyper <jameskuyper@verizon.net> - 2012-05-15 08:47 -0400
Re: Redundant return() Ian Collins <ian-news@hotmail.com> - 2012-05-16 08:01 +1200
Re: Redundant return() "BartC" <bc@freeuk.com> - 2012-05-15 22:58 +0100
Re: Redundant return() Ian Collins <ian-news@hotmail.com> - 2012-05-16 10:24 +1200
Re: Redundant return() James Kuyper <jameskuyper@verizon.net> - 2012-05-15 18:39 -0400
Re: Redundant return() nick_keighley_nospam@hotmail.com - 2012-05-16 02:45 -0700
Re: Redundant return() Noob <root@127.0.0.1> - 2012-05-16 13:34 +0200
csiph-web