Article View: comp.std.c
Article #3625Re: Wishful thinking: return-parameter
From: Jim Fleming
Date: Thu, 03 Aug 1995 03:27
Date: Thu, 03 Aug 1995 03:27
72 lines
3067 bytes
3067 bytes
In article <3viv5u$bkv@news.cs.tu-berlin.de>, mfx@cs.tu-berlin.de says...
>
>[...dubious-looking proposals for named return parameters deleted...]
>
>IMHO, there might be only _one_ good reason to include named return values
>into a future version of C: to simplify multiple return values.
>
>My proposal: separate the concepts of return-value and return-control-flow,
>and extend the function syntax to (for example)
>
>(int x, float y) foo (int a, char* b) { /* x,y return parameters */
> ...
> x = ....; /* assign to first return parameter */
> ...
> y = ... ; /* assign to the other return parameter */
> ...
> return; /* return from foo with whatever has been assigned to x,y */
>}
>
>[plus an multiple-assignment-statement to match such function results:
>
> int bar; float baz;
> (bar,baz) = foo(42,"test");
>]
>
>Then the standard function declaration
>
>int foo (...) {
> ...
> return (expr);
>}
>
>would be an abbreviation for
>
>(int _return) foo (...){
> ...
> _return = expr; return;
>}
>
>I have no idea whether this could be introduced painlessly in existing C. I
>guess that the syntax doesn't clash with any existing legal programs, and
>that the semantics doesn't have any problems, either. It might be useful to
>implicitly declare all return parameters as _register_ (to avoid
>address-taking).
>
>-- Markus (but is it worth the bother?)
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
This is exactly how it is done in C+@...:)
Was it worth the bother...????
I prefer methods which return a single value. In some cases there are
uses for multiple returns which work well if an entire project adopts
a common style.
For example, the left-most value can be the normal return, the next
value can be some error condition, and the right-most value can be
used only during the development process for tracing, debugging, etc.
BTW...I did not realize this thread was into multiple returns when
I posted my other request...
--
Jim Fleming /|\ Unir Corporation Unir Technology, Inc.
jrf@tiger.bytes.com / | \ One Naperville Plaza 184 Shuman Blvd. #100
%Techno Cat I / | \ Naperville, IL 60563 Naperville, IL 60563
East End, Tortola |____|___\ 1-708-505-5801 1-800-222-UNIR(8647)
British Virgin Islands__|______ 1-708-305-3277 (FAX) 1-708-305-0600
\__/-------\__/ http:199.3.34.13 telnet: port 5555
Smooth Sailing on Cruising C+@amarans ftp: 199.3.34.12 <-----stargate----+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\____to the end of the OuterNet_|
Technical Details
Message-ID:
<3vpfmd$nl6@News1.mcs.net>Path:
arc1-ca.pugleaf.net!news.mcs.net!usenetReferences:
<3ver2u$8bk@caip.rutgers.edu> <3vg8l8$5sd@myst.plaza.ds.adp.com> <3viv5u$bkv@news.cs.tu-berlin.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mcs.net!usenet From: jim.fleming@bytes.com (Jim Fleming) Newsgroups: comp.std.c Subject: Re: Wishful thinking: return-parameter Date: 3 Aug 1995 03:27:09 GMT Organization: Unir Corporation Message-ID: <3vpfmd$nl6@News1.mcs.net> References: <3ver2u$8bk@caip.rutgers.edu> <3vg8l8$5sd@myst.plaza.ds.adp.com> <3viv5u$bkv@news.cs.tu-berlin.de> NNTP-Posting-Host: pc11.bytes.com Mime-Version: 1.0 X-Newsreader: WinVN 0.93.14