This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]