On Thursday, 19 September 2013 at 13:02:15 UTC, Peter Alexander
wrote:
On Thursday, 19 September 2013 at 12:45:01 UTC, Joseph Rushton
Wakeling wrote:
On 19/09/13 14:19, Peter Alexander wrote:
You mean a separate copy from v?
But surely then the copy would *always* be the same in the
in-contract as it is
in the out-contract? What's the point?
It makes sense to be able to access v.old (or v.onEntry or
whatever you want to call it) in the out contract, as then you
could do some checks on the final value of v that are
dependent on its entry value.
Yes that makes sense, but I have no idea what the difference
between the input and output contracts are in the original
post. What errors will the output v != 0 check catch that the
input v != 0 test not catch if they both use the input value of
v?
That was a reduced example to show that v was modified. It
prevented running the actual output contract which was:
size_t msb(T)(T v)
in
{
assert(v != 0);
}
out(ret)
{
assert(2^^ret <= v);
assert(v < 2^^(ret + 1));
}
body
{
size_t ret = 0;
while(v >>= 1) ++ret;
return ret;
}
//----
I want to calculate the msb, and in the out contract, I want to
validate it is correct, by comparing it with what the input was.
In this case, this doesn't really work, since the input was
"consumed".