Should r.length of type ulong be supported on 32-bit systems?

Lodovico Giaretta via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 1 02:30:35 PDT 2016


On Saturday, 1 October 2016 at 02:31:23 UTC, Andrei Alexandrescu 
wrote:
> https://github.com/dlang/phobos/pull/4827 still allows that but 
> specifies that phobos algorithms are not required to. -- Andrei

I don't have much experience, but IMHO the length should be 
restricted to be any of the built-in unsigned integral types 
(ubyte, ushort, uint, size_t, ulong). This way, all comparisons 
for equality or inequality are defined and correct, and the 
common type exists and is the one you'd expect. Also, every other 
operation on them works as expected, because smaller types are 
widened and the absence of signed types guarantees no strange 
results.

The only problem that arises with this definition of length is 
that functions cannot take a length parameter as size_t, because 
that could truncate it. Possible solutions, ordered from the best 
to the worst:

1) functions should try not to take lengths; they should take 
ranges or slices, which can be queried for their length;
2) functions could take lengths as the greatest possible type 
(ulong);
3) functions could be parameterized on the length type;
4) a minority of functions could, if deemed really necessary (for 
performance or whatever), use size_t, and it should be documented 
that they expect the length to be limited by the addressable 
length of the machine, and for which reason they do.


More information about the Digitalmars-d mailing list