Why does sum not work in static arrays?

Tim K. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 6 04:36:35 PST 2015


On Sunday, 6 December 2015 at 12:27:49 UTC, cym13 wrote:
> A static array is a value type so it is passed by value to 
> functions.

Oh, right, I totally forgot about that. Thank you for reminding 
me.
And yes, I was not planning on doing that. I just have a local 
fixed-size array that I wanted to get the sum of...

> The solution is to slice it:   a1[].sum;   That way you avoid 
> the problem.

Thank you two.


Regards


More information about the Digitalmars-d-learn mailing list