How to pass in reference a fixed array in parameter

Kagamin spam at here.lot
Wed Jun 5 09:31:32 UTC 2024


On Tuesday, 4 June 2024 at 12:22:23 UTC, Eric P626 wrote:
> I try to create a 2D array of fixed length and pass it in 
> parameter as a reference. Normally, in C, I would have used a 
> pointer as parameter, and pass the address of the array.

Not obvious what you're trying to do. How would you do it in C? 
Use one dimensional array? You can use one dimensional array in D 
too. If dimensions of the maze are dynamic, you just write the 
maze creation function that allocates the maze as you want.

In simple case:

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

     s_cell [5][5] maze;
     print_maze (maze);

}

void print_maze (ref s_cell [5][5] maze )
{
}
```

With factory:

```
void main()
{
     s_cell[][] maze=make(5,5);
     print_maze(maze);
}

void print_maze(s_cell[][] maze)
{
}

s_cell[][] make(int width, int height)
{
}
```


More information about the Digitalmars-d-learn mailing list