Array Ambiguity
Bastiaan Veelo
Bastiaan at Veelo.net
Thu Dec 20 23:39:50 UTC 2018
On Thursday, 20 December 2018 at 23:18:45 UTC, bauss wrote:
> On Thursday, 20 December 2018 at 22:59:31 UTC, Your Name wrote:
>> Static + Dynamic arrays exhibit some really weird behavior.
>>
>> https://run.dlang.io/is/3RfmAb
>>
>> https://run.dlang.io/is/EP0SPw
>
> No weird behavior.
>
> The parameter as "int[] a" doesn't actually mean dynamic array.
> It means slice. It takes a slice of the static array.
>
> In the first example it picks static array because the compiler
> can make the array static since it's not mutated in the
> function.
I think fixed length arrays are passed by value, and so can be
mutated:
https://run.dlang.io/is/zs5w6b
>
> Like if you do the following:
> https://run.dlang.io/is/fwvd59
>
> Then it'll pick dynamic array.
The reason here is because of auto, not of ~=.
Bastiaan.
More information about the Digitalmars-d
mailing list