We need better documentation for functions with ranges and templates

anonymous via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 15 06:33:36 PST 2015


On 15.12.2015 15:03, rumbu wrote:
> There is no indication what happens if the range is undefined in D docs.
> In fact, inconsistent behavior:
> - it will return 0 in case of null arrays;
> - it will throw AccessViolation for null ranges (or probably segfault on
> Linux);

I don't think the behavior is inconsistent. A "null array" is rather 
different from a null pointer/reference. If anything is inconsistent, 
I'd say it's the meaning of `null` in the different contexts.

A null pointer may be considered "undefined", but a "null array" is 
certainly not undefined. A "null array" has a null pointer and a length 
of zero. The zero length makes it so that the null pointer won't be 
dereferenced.

Thinking about arrays in terms of null is probably misleading. Instead, 
I'd suggest to think in terms of the empty array []. It's the exact same 
value, but it's more obvious what's going on.


More information about the Digitalmars-d mailing list