Using

pragma pragma_member at pathlink.com
Wed Mar 1 12:50:42 PST 2006


In article <du3pd9$30tq$1 at digitaldaemon.com>, Lionello Lunesu says...
>
>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. 

Personally, I've always used .init whenever I had to guarantee a valid array,
even if it was empty.

# int[] arr = int[].init;

It gets a little sticky with compound array types, as the compiler doesn't like
this syntax:

# char[][char[]] dictionary = char[][char[]].init;

So I wind up having to use parentheses or an alias to tighten it up:

# char[][char[]] dictionary = (char[][char[]]).init;

# alias char[][char[]] Dictionary;
# Dictionary dictionary = Dictionary.init;

- EricAnderton at yahoo



More information about the Digitalmars-d mailing list