Static array with parameter based size?

Miguel L via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 11 22:49:14 PDT 2017


On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote:
> Hi
>
> I need to create a non-dynamic array like this
>
> void f(int x)
> {
> int[x] my_array;
> ...
>
> this does not compile as x value needs to be known at compile 
> time. The closest to this I can get is:
>
> void f(int x)
> {
> int[] my_array;
> my_array.length=x;
>
> but I don't really need a dynamic array as length is not going 
> to change inside f.
>
> What is the best way to do this?
>
> Also what is it possible in D to write a function that accepts 
> an static array of any size?
>
> Thanks in advance

Sorry, this post is duplicated. Yesterday forum was not working 
and i received an error when i was trying to post it. Please 
ignore it.


More information about the Digitalmars-d-learn mailing list