Using "[]" for empty array (instead of null)

Lionello Lunesu lio at remove.lunesu.com
Wed Mar 1 01:27:04 PST 2006


Subject says it all, what do you think?

I always found the "char[] ar = null;" suspicious. An array is not (just) a 
pointer. What happens with its length?

# if (ar == null)

Is "ar" an array, or pointer?
Is only the pointer tested? or the length too? and/or?
Shouldn't it be "is null"?

Some examples using "[]" :

# if (ar == [])    // is 'ar' empty? (meaning length==0)

# char[] somefunc() {
#   return [];        // return an empty array (by definition ptr null, 
length 0)
# }

I know it's not important and I can live well without it. Just musing. : )

L. 





More information about the Digitalmars-d mailing list