[comp.std.c] Return

mmengel@cuuxb.ATT.COM (Marc W. Mengel) (08/12/89)

	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@cuuxb.att.com
 						attmail!mmengel
 						...!{lll-crg|att}!cuuxb!mmengel

flee@shire.cs.psu.edu (Felix Lee) (08/12/89)

In <2987@cuuxb.ATT.COM>,
   mmengel@cuuxb.ATT.COM (Marc W. Mengel) asks:
> Is
>	{a,b,c} = f(x,y);
> really that much prettier than
>	f(x,y, &a,&b,&c);

Yes.  Much in the same way people write
	a = f(x);
rather than
	f(x, &a);
or
	call _f,1
	ld [%fp-0x8],%o0
	st %o0,[%fp-0x4]

You should say what you mean, not just mean what you say.

[Followups to comp.lang.misc.]
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!flee