std.conv.to can't convert to bool?

Jesse Phillips jessekphillips+D at gmail.com
Mon Mar 28 09:07:46 PDT 2011


Andrej Mitrovic Wrote:

> Wow not a minute later and I get bitten by my own solution. A C
> function returned 1 for a supported feature, and -1 otherwise. And of
> course -1 got converted to true, so then I had a bug in my code.
> 
> Damn silly C functions which return -1 when they should return 0.
> 
> Or damn me for not RTFM'ing.

Yeah, so the reason it doesn't do that conversion is because it will bite you.

Actually D already uses non-zero as true. Why do you need to cast it?


More information about the Digitalmars-d-learn mailing list