Thread overview |
---|
April 19, 2007 Make if statement with stricter test | ||||
---|---|---|---|---|
| ||||
if(AA) <-- invalid char[][char[]] k; if (k) // this code should be invalid, cause it could strongly be a typo or some porting mistake from some C source I hope if(identifier) only work for Bool & Pointer types |
April 19, 2007 Re: Make if statement with stricter test | ||||
---|---|---|---|---|
| ||||
Posted in reply to Davidl | Davidl Wrote:
> if(AA) <-- invalid
>
> char[][char[]] k;
> if (k) // this code should be invalid, cause it could strongly be a typo
> or some porting mistake from some
> C source
>
> I hope if(identifier) only work for Bool & Pointer types
For an AA, I believe this works out to length - the length of the char[][] keys;
if(k) I believe checks k.keys.length by virtue of being at *(&k), which is 0 until you assign it a buffer. This seems like the right behavior to me for an AA.
if(k) asks if k is a non-empty Associative Array.
|
April 20, 2007 Re: Make if statement with stricter test | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan | >> if(AA) <-- invalid
>>
>> char[][char[]] k;
>> if (k) // this code should be invalid, cause it could strongly be a typo
>> or some porting mistake from some
>> C source
>>
>> I hope if(identifier) only work for Bool & Pointer types
>
> For an AA, I believe this works out to length - the length of the char[][] keys;
>
> if(k) I believe checks k.keys.length by virtue of being at *(&k), which is 0 until you assign it a buffer. This seems like the right behavior to me for an AA.
>
> if(k) asks if k is a non-empty Associative Array.
>
no if(k) doesn't indicate an empty AA, it just tests whether it has ever been used.
if k has been used and then cleared, still if(k) test would pass
|
Copyright © 1999-2021 by the D Language Foundation