Boost logo

Boost :

Subject: Re: [boost] [contract] Released Contract Programming Library on SourceForge
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2010-02-28 16:57:29


> I have released on SourceForge a library that implements Contract
> Programming (a.k.a. Design by Contract(TM) ) for C++. I am considering
> to submit this library to Boost (as Boost.Contract).
> Comments?

Hi,
Just another thought for a tiny extension that came to my mind. I
tried to use the block invariant as a regular assert:

  int main() {
    CONTRACT_ASSERT_BLOCK_INVARIANT( fee fee fee );
  }

This code compiles and works fine. This is because "disabling block
invariants" means that the entire macro invocation will disappear,
inclusive of the nonsense I wrote inside. We are used to it because
this is how C-style asserts work, but one of the advantage of asserts
over comments, as it is often advertised, is that the predicates are
checked for syntactic and (to some extent) semantic correctness. But
this is not the case if we disable the assertion macros.
I believe, it would be useful if "disabling block invariants" meant no
run-time overhead, but still checking syntactic correctness. It would
be possible if the macro

  CONTRACT_ASSERT_BLOCK_INVARIANT( expression );

were replaced with something like:

  ... sizeof( expression ) ...

then, the expression is not evaluated, but required to be correct. If
the value of sizeof is not used it should be eliminated by the
compiler. Obviously, the same would be applicable for all the other
types of checks,

Regards,
&rzej


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk