SuperC documentation

Default arguments in functions

Unlike C, SuperC allows parameters to have optional default values.

Named arguments

When a parameter has a default value, it can be selected by name instead of position.

Note that the order of the arguments does not matter when they are selected by name.

Collision with function overloading

Have in mind the following example, which foo gets called?

  1. Overloads that do not require default arguments are preferred.
  2. Overloads with fewer default arguments are preferred.

The answer is foo1

void foo(int a)            __attribute__((symbol("foo1")));
void foo(int a, int b = 0) __attribute__((symbol("foo2")));

int main() {
  foo((int)10);
  return 0;
}

Previous

Function overload

Next

Namespaces
Playground