www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - More fun with bools

Anyone tried this?  :)

int main()
{
    bool b = true;
    if (b) printf("true\n"); else printf("false\n");

    b = ~b;
    if (b) printf("true\n"); else printf("false\n");

    return 0;
}
Prints: true true This is actually a known bug, which I'm sure Walter will fix soon. The unary operator ~ complements the internal representation of b, from 0x01 to 0xFE, which tests as non-zero. Of course, you can replace ~ with ! and it works fine. Jill
Jun 16 2004