Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-09-01 06:08:00


Greg Colvin wrote:
>
> From: Valentin Bonnard <Bonnard.V_at_[hidden]>
> > Kevlin Henney wrote:
> >
> > > Valentin Bonnard wrote:
> > > [...]
> > > > For boost library authors, the first need is perhaps not as great as
> > > > that for a user dotting their own code w/ assertions. Naming and
> > > > describing what constraint was violated is often more useful to a
> > > > library user than receiving a mysterious message about a piece of code
> > > > they have nothing to do w/!
> > >
> > > This can easilly be done with a comment:
> > >
> > > // must fobnicate before we tweak
> > > assert (x ? t(3) : 3434==i+j);
> > >
> > > And there was me thinking that the compiler ignored comments ;-)
> > >
> > > If you wish to do this 'properly' w/ assert:
> > >
> > > assert (("must fobnicate before we tweak", x ? t(3) : 3434==i+j));
> >
> > Then the string will take space in the program (I have read
> > that it was a problem for big apps).
>
> Unless the translator removes duplicate string literals?

I have read this assertion (oops, sorry) in a book about
C, so inline functions weren't a problem, written by someone
from MS.

Anyway, I think that it's cleaner to send explanations
to STDERR than the expression used in the assertion,
which doesn't make much sens w/o its context (what is
x, i, j ? you may ask).

> > I would rather add an argument to assertion:
> >
> > assertion ("must fobnicate before we tweak", x ? t(3) : 3434==i+j);
>
> How does this use less space?

If you use an empty string it does use less code space.
Otherwise it doesn't.

I sent the reply about code space just because I forgot
the #cond in the macro definition and I didn't wanted to
admit that.

> Anyway, I prefer the string to be an optional second argument:
> assertion (x ? t(3) : 3434==i+j, "must fobnicate before we tweak");

Good idea

-- 
Valentin Bonnard

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