create and initialise array
mw
mingwu at gmail.com
Sat Sep 19 21:53:34 UTC 2020
On Thursday, 20 June 2019 at 07:57:25 UTC, KnightMare wrote:
> On Thursday, 20 June 2019 at 01:32:04 UTC, matheus wrote:
>>>
>> import std.stdio;
>> import std.array;
>>
>> void main(){
>> auto s = uninitializedArray!(float[])(100);
>> s[] = 0.0f;
>> writeln(s[0]);
>> }
Even with this, user has to write two statement, why we can't
just have:
auto s = new float[100](0);
> another version:
> auto arr = new double[ 10 ];
> writeln( arr[5] ); // NaN
> arr.length += 10;
> writeln( arr[15] ); // NaN
>
> imo NaN is useless, weird and unusual coz integrals and
> pointers are "all bits zeroes" but float and chars are "all
> bits ones". WTF? its strange that bool.init is false in such
> case.
> .init = "all zeroes" can be faster initialize any block of
> memory.
I have the same question, why float/double are init to NaN,
instead of 0? as other post-C++ language does? e.g Java, C# ...
What's the reason for this design decision?
More information about the Digitalmars-d-learn
mailing list