length's type.
mw
mw at g.c
Sun Jan 28 17:25:49 UTC 2024
On Sunday, 28 January 2024 at 16:16:34 UTC, Olivier Pisano wrote:
>
> If .length were to be an int, D could not handle array of more
> than 2G bytes. The whole language would be useless on 64 bit
> systems.
The array.length better to be *signed* `long` (signed size_t)
instead of unsigned.
Can you guess what is the output of this array element average
calculation example:
==================================
import std.algorithm;
import std.stdio;
void main() {
long[] a = [-5000, 0];
long c = sum(a) / a.length;
writeln(c);
}
==================================
See the result here:
https://forum.dlang.org/post/cagloplexjfzubncxuza@forum.dlang.org
More information about the Digitalmars-d-learn
mailing list