Thread overview | |||||
---|---|---|---|---|---|
|
January 14, 2004 question: evaluations | ||||
---|---|---|---|---|
| ||||
in vb anything that isnt 0 evaluates to true, is this the same in d? //example char[] foo; foo.length = 1; if (foo.length) { } //or uint x; x = -1; if (x) { } //or while (x) { } thanks |
January 14, 2004 Re: question: evaluations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lewis | Lewis wrote:
> in vb anything that isnt 0 evaluates to true, is this the same in d?
>
> //example
>
> char[] foo;
> foo.length = 1;
>
> if (foo.length) {
>
> }
>
> //or
>
> uint x;
> x = -1;
> if (x) { }
>
> //or
> while (x) { }
>
>
> thanks
Yes, it's the same in C and C++ as well. One difference is that the literal true = 1 in these languages. In VB the literal true = -1; It's particularly useful for pointers, which are null (0) if they don't have anything in them.
int* p;
if (p)
{
//There's something in p
}
|
January 15, 2004 Re: question: evaluations | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | J Anderson wrote:
> Lewis wrote:
>
>> in vb anything that isnt 0 evaluates to true, is this the same in d?
>>
>> //example
>>
>> char[] foo;
>> foo.length = 1;
>>
>> if (foo.length) {
>>
>> }
>>
>> //or
>>
>> uint x;
>> x = -1;
>> if (x) { }
>>
>> //or
>> while (x) { }
>>
>>
>> thanks
>
>
> Yes, it's the same in C and C++ as well. One difference is that the literal true = 1 in these languages. In VB the literal true = -1; It's particularly useful for pointers, which are null (0) if they don't have anything in them.
>
> int* p;
>
> if (p)
> {
> //There's something in p
> }
>
neato! thanks Mr. Anderson
|
Copyright © 1999-2021 by the D Language Foundation