This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: something that would be nice
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: "Matt Wells" <mwells at gigablast dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 11 Nov 2003 23:57:49 +0100
- Subject: Re: something that would be nice
- Organization: Integrable Solutions
- References: <007001c3a8a6$204a8ce0$0201a8c0@home>
"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