char[] == null
BBaz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 19 03:02:22 PST 2015
On Wednesday, 18 November 2015 at 20:57:08 UTC, Spacen Jasset
wrote:
> Should this be allowed ?
IMHO no.
It's better to use `.length` to test if an array is empty. Why ?
Because the day you'll have a function whose parameter is a
pointer to an array, comparing to null will become completly
confusing:
---
void whyPeopleShouldUseLength(char[]* buffptr)
{
if (buffptr != null && buffptr.length > 0) {}
}
---
Here you really have to test if the variable is assigned, it's
not a shortcut to test the internal buffptr `.ptr` member.
More information about the Digitalmars-d-learn
mailing list