Skip to content

Commit

Permalink
Update splat information for varargs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jul 21, 2024
1 parent 7dd4300 commit 98ac475
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions src/content/docs/references/docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,45 @@ There are four types of varargs:

Examples:

fn void va_singletyped(int... args)
{
/* args has type int[] */
}
```c3
fn void va_singletyped(int... args)
{
/* args has type int[] */
fn void va_variants_explicit(any*... args)
{
/* args has type any*[] */
}
fn void va_variants_explicit(any*... args)
{
/* args has type any*[] */
fn void va_variants_implicit(args...)
{
/* args has type any*[] */
}
fn void va_variants_implicit(args...)
{
/* args has type any*[] */
}
extern fn void va_untyped(...); // only used for extern C functions
fn void test()
{
va_singletyped(1, 2, 3);
extern fn void va_untyped(...); // only used for extern C functions
int x = 1;
any* v = &x;
va_variants_explicit(&&1, &x, v); // pass references for non-any arguments
fn void test()
{
va_singletyped(1, 2, 3);
int x = 1;
any* v = &x;
va_variants_explicit(&&1, &x, v); // pass references for non-any arguments
va_variants_implicit(1, x, "foo"); // arguments are implicitly converted to anys
va_untyped(1, x, "foo"); // extern C-function
}
va_variants_implicit(1, x, "foo"); // arguments are implicitly converted to anys
va_untyped(1, x, "foo"); // extern C-function
}
```

For typed varargs, we can pass a slice instead of the arguments, by using the `...` operator:

```c3
fn void test_splat()
{
int[] x = { 1, 2, 3 };
va_singletyped(...x);
}
```

### Functions and optional returns

Expand Down

0 comments on commit 98ac475

Please sign in to comment.