DMD 0.149 release (on bools)
Wang Zhen
nehzgnaw at gmail.com
Tue Mar 7 19:01:37 PST 2006
Derek Parnell wrote:
> On Tue, 07 Mar 2006 18:12:41 -0800, BCS wrote:
>
>
>>>It's not like anybody would want to write exactly
>>>
>>> bool x = 5;
>>>
>>>but more like
>>>
>>> bool x = strcmp("foo", "bar");
>>> if (!x) { /* do stuff */ } // match
>>> else { /* call the cops! */ } // no match
>>>
>>
>>"!!" ends up as a cast to bool
>>
>>try:
>>
>>import std.stdio;
>>
>>int main()
>>{
>> int i = 1;
>> int j = 2;
>> int k = 0;
>>
>> if(!!i)writef("i\n");else writef("!i\n");
>> if(!!j)writef("j\n");else writef("!j\n");
>> if(!!k)writef("k\n");else writef("!k\n");
>>
>> return 0;
>>}
>
>
> LOL.... try this too.
>
> writefln("%s %s", !!i, !!k);
>
> I get "true false" in return.
>
> Now this qualifies as a real D-Geek operator.
>
This is an old C idiom.
More information about the Digitalmars-d-announce
mailing list