if(arr) now a warning

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 20 10:58:29 PDT 2015


On 4/20/15 12:14 PM, Kagamin wrote:
> On Sunday, 19 April 2015 at 08:05:46 UTC, Jonathan M Davis wrote:
>> the C folks would think that
>> the current behavior of it being equivalent to if(arr is null) would
>> be more
>> intuitive, since they're used to thinking of arrays as pointers.
>
> Are they used to disregard value types too? I don't see it working in C:
> http://ideone.com/rzSSlx

Not exactly. Because C arrays are pointers, it does work that way:

void foo(int c[])
{
    if(c) {...} // same as if(c is null)
}

But C doesn't have any other possible piece to check, as the length of 
the array is not part of the code.

The closest equivalent is C++ vectors, and if(someVector) doesn't work.

-Steve


More information about the Digitalmars-d mailing list