out contract misunderstanding (was: I cannot understand problem with argument of the function)

Ivan Kazmenko gassa at mail.ru
Wed Sep 18 23:38:56 PDT 2013


On Thursday, 19 September 2013 at 01:41:15 UTC, mrd wrote:
> $ ./bug
> body, value=2
> out contract, value=0
>
> Why argument "value" in contract isn't equal 2 ?

Why should it be?  value is a mutable argument, and the out 
contract evaluates it at the return point, which is after it's 
set to 0.  It is no different than using value in the body just 
before the return point.

If you want to preserve the original arguments until the return 
point, use const and create a mutable duplicate.

Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list