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

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 1 01:09:45 PDT 2016


On Friday, September 30, 2016 22:31:23 Andrei Alexandrescu via Digitalmars-d 
wrote:
> https://github.com/dlang/phobos/pull/4827 still allows that but
> specifies that phobos algorithms are not required to. -- Andrei

Every time this comes up, I strongly argue in favor of requiring that length
be size_t. Occasionally, that restriction is annoying, but allowing anything
else plays havoc with generic code. It's even worse when you have to start
dealing with the fact that the same code needs to compile and function the
same on both 32-bit and 64-bit systems.

At one point, iota was changed to support lengths of long or ulong in order
to give you the full range of numbers for a range of long or ulong on 32-bit
systems, and that's caused us a fair bit of grief in various places in
Phobos, because everything was assuming that length was size_t and doing
anything else can get fairly complicated. And I think that it's still the
case that a fair bit of Phobos will fall flat on its face when dealing with
a length that isn't size_t. Fortunately, it looks like iota was finally
fixed to use size_t for length again.

This is some loss of expressiveness as a result of requiring that length be
size_t, but it's rarely a problem, and it simplifies code that deals with
length significantly.

- Jonathan M Davis



More information about the Digitalmars-d mailing list