Home Demos Forum Research Guide
Viewing topic in forum 'general'
back to topic list

Function overload and variadic functions
Is it possible to create functions with the same name with different params in Dana? What about creating a function with unknown number of params?

I couldn't find any of that in the Programming Guide.

Thanks!

- Roberto
by roberto on 2015-03-06 03:20:24 (2 replies)

Hi, I'm afraid neither of these is currently possible :-/

The ability to have multiple same-named functions (including constructors) is planned for a future update. There are no plans at the moment to support functions with unknown / variable parameter lists; I guess you can potentially imitate this to some extent by having a Data[] array as a parameter and populating the array with your additional parameters.

I'd be interested to know if there are particular cases where there's no other way to achieve something without having a variable parameter list though...?

- Barry
by barry on 2015-03-06 04:17:14
I intended to use those features for cosmetic purposes - to keep code organised and clean. I think we can pretty much come up with workarounds like having Data[] for the unknown multiple argument thingy, in the end that is what they do in C anyway.


add_em_up (int count,...)
{
  va_list ap;
  int i, sum;

  va_start (ap, count);         /* Initialize the argument list. */

  sum = 0;
  for (i = 0; i < count; i++)
    sum += va_arg (ap, int);    /* Get the next argument value. */

  va_end (ap);                  /* Clean up. */
  return sum;
}
 

This code's from: http://www.gnu.org/software/libc/manual/html_node/Variadic-Example.html#Variadic-Example

And that just makes printf function look so much better. If we'd have that, out.println would look better too (:
by roberto on 2015-03-06 05:09:07
© Francis Research Ltd. 2017