an old topic (pun intended)

bearophile bearophileHUGS at lycos.com
Sat Oct 29 20:26:58 PDT 2011


Davidson Corry:

> The only reason to have an 'out(result)' form is to declare that we 
> intend to use the magic 'result' symbol in the post-condition testing.

This is not true. Currently 'result' has nothing magic, it's just a variable name, you are free to change it:


int result;
int foo(int x, out int result)
    out(y) {
        assert(y > 0);
    }
    body {
        result = 10;
        return -1;
    }
void main() {
    int z;
    auto s = foo(4, z);
}


> I think the thing to do is to just declare 'out' as we currently do [or 
> 'scope(out)' as I am proposing], and treat the 'result' symbol magically 
> in the post-condition code whether or not it is pre-declared -- that is, 
> have the compiler find it and interpret it as the magic returned-value.

In some rare situations magic is acceptable, but it's dangerous, and in most situations it's better to avoid it. Unless "result" becomes a keyword (so you can't assign something to it by mistake), then the current syntax with out(someConstVariableName) seems better.

Bye,
bearophile


More information about the Digitalmars-d mailing list