comparing pointers passed to and returned from funcs

bearophile bearophileHUGS at lycos.com
Tue Mar 1 15:00:53 PST 2011


This seems to work:

import core.stdc.stdio: printf;
struct Foo {
    bool b;
    this(bool b_) { this.b = b_; }
}
const(Foo)* TRUE, FALSE;
static this() {
    TRUE = new const(Foo)(true);
    FALSE = new const(Foo)(false);
}
const(Foo)* not(const(Foo)* op) {
    return (op == TRUE) ? FALSE : TRUE;
}
void main() {
    assert(not(TRUE) == FALSE);
    printf("%x\n", TRUE);
    printf("%x\n", FALSE);
    printf("%x\n", not(TRUE));
    printf("%x\n", not(not(TRUE)));
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list