contract programming without a function

Jan Hanselaer jan.hanselaer at gmail.com
Sat May 19 14:30:00 PDT 2007


Hi

In the manual http://www.digitalmars.com/d/dbc.html I read  :
" The pre contracts specify the preconditions before a statement is 
executed. The most typical use of this would be in validating the parameters 
to a function. The post contracts validate the result of the statement. The 
most typical use of this would be in validating the return value of a 
function and of any side effects it has. "
Makes sense to me. What I ask myself is if it's useful elsewhere and 
especially is it possible in D? I tried it with a little example.

void main()
{
   bool assign = true;
   int x;
   in{
      assert(assign);
   }
   body{
      x = 1;
   }
}


It wont compile ("found in instead of statement"). I know it's not exactly a 
useful example but I just wanted to check if it was possible. I thought it 
would be because nowhere es said it's not possible. Did I just made a 
programming error or is it really not possible?

Greetings
Jan





More information about the Digitalmars-d-learn mailing list