null == "" is true?
user1234
user1234 at 12.de
Tue Jul 12 19:02:01 UTC 2022
On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote:
> On Tue, Jul 12, 2022 at 04:27:44PM +0000, Antonio via
> Digitalmars-d-learn wrote:
>> It works
>>
>> ```d
>> void main()
>> {
>> assert(null=="");
>> }
>> ```
>>
>> why?
>
> Because an empty string is, by default, represented by an empty
> slice of the null pointer.
>
> Do not rely on this, however;
Absolutely. I'd like to add: especially as default parameter
value that's an array. Never use null. use `[]` (empty array
literal).
More information about the Digitalmars-d-learn
mailing list