How to pass in reference a fixed array in parameter

Nick Treleaven nick at geany.org
Wed Jun 5 10:27:47 UTC 2024


On Tuesday, 4 June 2024 at 12:22:23 UTC, Eric P626 wrote:
> ~~~
> void main()
> {  writeln("Maze generation demo");
>
>    s_cell [5][5] maze;
>    print_maze (maze);
>
> }
>
> void print_maze ( s_cell [][] maze )
> {
> }
> ~~~

This is how to do it without GC allocations (I have used `int` 
instead for demo purposes):

```d
import std.stdio;
alias s_cell = int;

void main()
{  writeln("Maze generation demo");

    s_cell [5][5] maze = [0, 1, 2, 3, 4];
    s_cell[][5] slices; // static array of 5 slices
    foreach (i, row; maze)
        slices[i] = row;

    print_maze (slices);
}

//~ void print_maze ( s_cell [][] maze... )
void print_maze ( s_cell [][] maze )
{
     foreach (a; maze)
         a.writeln();
}
```


More information about the Digitalmars-d-learn mailing list