In the last exercise (05
), I ran quickly tried to extend it into creating "unfloored halves" (you'll know what I mean if you look at the exercise) ... and ran into the process of initialising empty arrays.
What I hit upon is:
let mut floating_data: [f32; 5] = [0.0; 5];
Where the 0.0
in [0.0; 5]
is necessary it seems?? And you can't simply have let floating_data = [f32; 5];
... ?
From what I gathered, the general syntax is [EXPR; SIZE]
, where EXPR
is actually evaluated, presumably to define the required memory/type, even though the type of the array (in the code above, f32
) also constrains the type of elements of the array.
In the code above, as the default float type is f64
, the typing of the array as [f32; 5]
actually constrained or affected the way that the expression of 0.0
in the array literal was used to build the array.
So why do I need to provide both so that they interact in this weird and implicit way?? Unless I'm missing something, surely something like let floating_data = [f32; 5];
would be better? Putting that 0.0
because it just needs to be there is tolerable but a bit off IMO.