Return (errors, multi-items, etc.)

Marc W. Mengel mmengel at cuuxb.ATT.COM
Sat Aug 12 04:04:18 AEST 1989


	Several folks have posted discussions of how we ought
	to extend C to do things like

		{a,b,c} = f(x,y);

	or
		if( error( y = f(x) ) ) { ... }

	There is a very simple pardigm you can use in C for these
	sorts of things.   Simply using

		int
		MapxyToabc( x, y, a, b, c )
			int x,y,*a,*b,*c;
		{
			*a=x+y;
			*b=x-y;
			...
			return 1;
		}


	Then you can have multiple return values via multiple 
	pointer to result arguments, and a  true/false or
	0..n error code result that you can use in guarded
	statements like

		if( f(x,y,&a,&b,&c) ) {...}

	In short, why extend the language?  We can already
	do these things, without changing the language.
	Is

		{a,b,c} = f(x,y);

	really that much prettier than

		f(x,y, &a,&b,&c);

	???
-- 
 Marc Mengel					mmengel at cuuxb.att.com
 						attmail!mmengel
 						...!{lll-crg|att}!cuuxb!mmengel



More information about the Comp.std.c mailing list