This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: something that would be nice
Gabriel, Thanks for the response!
But having to define a Result struct for each of my functions
does not simplify things. I think it actually is more complicated
and messy than passing in pointers as parameters.
The code you added below undoubtedly works, but it
doubles the number of lines and makes things a lot more
confusing to look at. I have hundreds of these functions
and I'd prefer not to have to declare a Results structure
for each one.
Matt
----- Original Message -----
From: "Gabriel Dos Reis" <gdr@integrable-solutions.net>
To: "Matt Wells" <mwells@gigablast.com>
Cc: <gcc@gcc.gnu.org>
Sent: Tuesday, November 11, 2003 3:57 PM
Subject: Re: something that would be nice
> "Matt Wells" <mwells@gigablast.com> writes:
>
>
> [...]
>
> | So my question is... would it be easy to make functions return multiple
> | values?
> |
> | For example:
>
> struct Result {
> int value;
> int status;
> };
>
> static inline Result result(int value, int status)
> {
> Result res = { value, status };
> return res;
> }
>
> Result myfunction(int a, int b, c) {
> return result(a + b + c, 0);
> };
>
> | main () {
> | int value , myerrno ;
> | value , myerrno = myfunction ( a,b,c );
>
> Result r = myfunction (a, b, c);
>
> [...]
>
> | This is more in line with mathematics, too. A function can map
> | an N dimensional point to an M dimensional point.
>
> Yep, it is called product type has been in C since the dark ages.
>
> | What do you guys think about this?
>
> Me thinks it is already in the language.
>
> | Is it a common request?
>
> If you were using C++, I would say that the common idiom is that of
> Faillible<T> of Barton & Nackman.
>
> -- Gaby
>