Thread overview
question: evaluations
Jan 14, 2004
Lewis
Jan 14, 2004
J Anderson
Jan 15, 2004
Lewis
January 14, 2004
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
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
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