Thread overview
direct access to ...
Mar 13, 2004
Andrew Edwards
Mar 13, 2004
J C Calvarese
Mar 13, 2004
Ben Hinkle
Mar 14, 2004
Manfred Nowak
March 13, 2004
call me crazy, but I think that the ... perameter should facilitate direct access to arguments provided during called.

for example:

void multiArgs(...)
{
  // uniquely identify each argument provided during function call
  typeof(arg1) a1 = arg1;
  typeof(arg2) a2 = arg2;
  typeof(arg3) a3 = arg3;
  .
  .
  .

  // process arguments
}

int i;
char c;
double d;

multiArgs(i,c,d);

I should be able to access i, c, and d directly in multiArgs().
If this is possible, please demonstrate or provide a link to the documentation.
Otherwise, please consider including this feature.

Andrew

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
March 13, 2004
Andrew Edwards wrote:

> call me crazy, but I think that the ... perameter should facilitate direct access to arguments provided during called.

You're not crazy, D could benefit from some flexible variable arguments techniques. Also, it would help us draw in Visual Basic users. More comments below...

> 
> for example:
> 
> void multiArgs(...)
> {
>   // uniquely identify each argument provided during function call
>   typeof(arg1) a1 = arg1;
>   typeof(arg2) a2 = arg2;
>   typeof(arg3) a3 = arg3;
>   .
>   .
>   .
> 
>   // process arguments
> }
> 
> int i;
> char c;
> double d;
> 
> multiArgs(i,c,d);
> 
> I should be able to access i, c, and d directly in multiArgs().
> If this is possible, please demonstrate or provide a link to the documentation.

I think this is the closest thing I've seen yet:
http://www.digitalmars.com/drn-bin/wwwnews?D/25034

The catch is that it requires that all of the types have to be the same. I hate to suggest this (because I can already envision the derisive laughter), but does D need some kind of variant type?


If it's possible, I'd like to know how to do this, too. I think a lot of cool things could be done with this feature.

> Otherwise, please consider including this feature.
> 
> Andrew
> 

-- 
Justin
http://jcc_7.tripod.com/d/
March 13, 2004
"Andrew Edwards" <remove_ridimz@remove_yahoo.com> wrote in message news:opr4tgk5bms6zaqn@news.digitalmars.com...
> call me crazy, but I think that the ... perameter should facilitate direct access to arguments provided during called.
>
> for example:
>
> void multiArgs(...)
> {
>    // uniquely identify each argument provided during function call
>    typeof(arg1) a1 = arg1;
>    typeof(arg2) a2 = arg2;
>    typeof(arg3) a3 = arg3;
>    .
>    .
>    .
>
>    // process arguments
> }
>
> int i;
> char c;
> double d;
>
> multiArgs(i,c,d);

There are a couple of technical challenges here:

1) typeof is resolved at compile-time and the declaration of multiArgs doesn't tell D anything about the types of the inputs, or how maybe inputs there are at the call site.

2) the call multiArgs(i,c,d) puts the int,char and double on the stack without any information about what types are now on the stack. The multiArgs body doesn't know if the stack has int,int,int or char or anything else.

So, without some serious modification of what functions declared with ... do I think your best bet is to use either templates or function overloading.

If we do start playing around with vararg functions, I think it would be
reasonable to have the current behavior for non-D linkage functions and the
following for D functions. When the compiler determines that arguments x_1,
x_2 ... x_n are vararg parameters it puts on the stack:
  n (as a uint)
  pointer to an instance of the TypeInfo of x_1
  x_1
  pointer to an instance of the TypeInfo of x_2
  x_2
  etc up to x_n

I'm not sure exactly how useful those TypeInfos would be, but they do have the size and some other useful things. You still wouldn't be able to tell for example a uint from an int, though.


> I should be able to access i, c, and d directly in multiArgs().
> If this is possible, please demonstrate or provide a link to the
> documentation.
> Otherwise, please consider including this feature.
>
> Andrew
>
> -- 
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


March 14, 2004
Andrew Edwards wrote:

[...]
>    // process arguments
[...]
> multiArgs(i,c,d);

The crux of your wish is hidden in the comment `process arguments'.

Please provide a somehow useful example of processing arguments, when `multiArgs' can be called with actual parameters `i', `c' and `d' in an arbritary permutation.

To enrich your imagination I want you to even show, that you can provide some useful code when enriching the call of your `multiArgs' with some function pointers of different formal parameter lists, associative arrays, strings, string arrays etc.

In case your imagination fails, please show only that you can print out the string that is provided somewhere in the parameter list.

So long.