The D Programming Language

Richard Harter g-rh at cca.CCA.COM
Sat Mar 5 16:30:53 AEST 1988


Here is another feature for D whose absence in C has been irksome to
me -- I would like to be able to return several items from a function.
The problem is that arguments to C are passed by copying the value --
this is loverly since it means that my function can't munge the stuff
passed to it.  But how do I get stuff back.  I can pass one thing back
via the return statement.  To pass more than one thing I have to play
games.  Things which are returned need a mechanism equivalent to pass
by address.

An ancient and venerable way to handle this is to have 'in', 'out', and
'update' qualifiers for arguments.  I have seen this used in several
languages, and my observation is that it doesn't work; people end up
bypassing the mechanism.

The following example is illustrative syntax only:

[int *,int] foobar();
....
[ptr,flag] = foobar(arg)
   int arg;
{
   int *a, *b;
   ....
   return [a,1];
   ....
   return [b,0];
}


 
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list