This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: something that would be nice
- From: "Marty Hauff" <marty dot hauff at rmit dot edu dot au>
- To: <gcc at gcc dot gnu dot org>, <mwells at gigablast dot com>
- Date: Wed, 12 Nov 2003 14:31:02 +1100
- Subject: Re: something that would be nice
Without stating the obvious, is there any reason why you couldn't use a macro? OK its a bit clunky but it would work!
#define RETURN(x, y) {err_code = y; return(x);}
int err_code = 0;
char MyCharFunc(void)
{
RETURN('c',1);
}
int MyIntFunc(void)
{
RETURN(25, 2);
}
void main(void)
{
char ch;
int i;
ch = MyCharFunc();
printf ("\nAfter MyCharFunc() result is %c, err_code is %d", ch, err_code);
i = MyIntFunc();
printf ("\nAfter MyIntFunc() resut is %d, err_code is %d", i, err_code);
}
Just a thought
Marty Moose
>>> "Matt Wells" <mwells@gigablast.com> 11/12/03 09:49 AM >>>
Hi,
My name is Matt Wells and I'm the sole creator of the internet's soon-to-be
largest search engine, http://www.gigablast.com/ .
I have many functions that return an integer value, positive, zero or
negative so I can't really say "this function returns -1 and
sets errno on error" because -1 is a legit value for my
function to return. Passing in a pointer to the extra value(s) I would like
returned is, in my view, sloppy and potentially confusing.
So my question is... would it be easy to make functions return multiple
values?
For example:
main () {
int value , myerrno ;
value , myerrno = myfunction ( a,b,c );
// or even
( value , myerrno ) = myfunction ( a , b , c );
}
int , int myfunction ( int a , int b , int c ) {
return a + b + c , 0;
// or
return ( a + b + c , 0 );
}
This is more in line with mathematics, too. A function can map
an N dimensional point to an M dimensional point.
What do you guys think about this?
Is it a common request?
Matt