🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3659

Re: Wishful thinking: return-parameter

#3659
From: Zefram
Date: Sat, 05 Aug 1995 09:10
29 lines
1597 bytes
Stephen Baynes <baynes@ukpsshp1.serigate.philips.nl> wrote:
>How about using the 'else' keyword:
>
>int fn() ret
>{
> if(some_error_condition()) { 
>     ret=-1; 
> }else{
>     /* ... */
> }
>}

That doesn't express the intended flow of control.  The intention is
that if some_error_condition() then the function returns an error
indication immediately.  The above code says "if there is an error, set
the return value to -1, otherwise do /* ... */".  This is completely
different.  It's also ugly to have the main body of the code, which is
intended to be executed under "normal" circumstances (i.e. non-error),
in a conditional.

>It is a much better way to do it anyway even in current C as it makes
>maitenace simpler (consider adding code to end of function to be done
>on all returns).

Often one doesn't want that for error returns, and the alternative with
a goto (or break, in some cases) is understandable.  You're right here
in some cases, but return parameters don't make that any easier.

-zefram
Technical Details
Message-ID: <1995Aug5.091033.15742@dcs.warwick.ac.uk>
Path: arc1-ca.pugleaf.net!news.dcs.warwick.ac.uk!not-for-mail
References: <3ver2u$8bk@caip.rutgers.edu> <3vjjl6$7nm@caip.rutgers.edu> <1995Aug2.080237.17479@dcs.warwick.ac.uk> <DCq4py.Mpq@ukpsshp1.serigate.philips.nl>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!news.dcs.warwick.ac.uk!not-for-mail
From: A.Main@dcs.warwick.ac.uk (Zefram)
Subject: Re: Wishful thinking: return-parameter
X-Nntp-Posting-Host: stone
Message-ID: <1995Aug5.091033.15742@dcs.warwick.ac.uk>
Sender: news@dcs.warwick.ac.uk (Network News)
Organization: Department of Computer Science, Warwick University, England
References: <3ver2u$8bk@caip.rutgers.edu> <3vjjl6$7nm@caip.rutgers.edu> <1995Aug2.080237.17479@dcs.warwick.ac.uk> <DCq4py.Mpq@ukpsshp1.serigate.philips.nl>
Date: Sat, 5 Aug 1995 09:10:33 GMT