if(arr) now a warning

Kagamin via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 22 03:19:01 PDT 2015


On Monday, 20 April 2015 at 18:01:20 UTC, Jonathan M Davis wrote:
> An array in C is a pointer, not a struct.

True. I only question the claim that they don't care about such 
things.
Also difference between pointer and reference types seems to be 
no problem for STL string. If it wasn't designed by C 
programmers, then by whom?

> So, the obvious thing for a C programmer when they see
>
> if(arr)
>
> would be to think that it was equivalent to
>
> if(arr != NULL)

Don't you contradict yourself now?
arr!=null is equivalent to arr.length!=0

> D tries to avoid segfaulting for null arrays

In fact nothing like that ever happened. Bug 14436 exists because 
there was never any special treatment for null slices.


More information about the Digitalmars-d mailing list