Boost logo

Boost :

Subject: Re: [boost] suggestion on assertion macros
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2010-03-15 21:32:46

On Mon, Mar 15, 2010 at 11:19 AM, Roland Bock <rbock_at_[hidden]> wrote:
> Emil Dotchevski wrote:
>> On Mon, Mar 15, 2010 at 10:28 AM, Roland Bock <rbock_at_[hidden]> wrote:
>>>  #define assert(cond) static_cast<void>(sizeof(cond? 0: 0));
>> Presumably, (void)sizeof(cond?0:0) gives you a warning for using
>> C-style cast? :)
> Not that I know of  :-) . I prefer C++ style because they are more easy to
> spot than C style (e.g. by searching for "static_cast").

Yeah, that's one of the reasons why C++ casts exist: to be able to
spot dangerous casts in the code. Except that in this case we're not
casting anything; static_cast here only makes other dangerous casts
harder to spot.

>> How about disabling a few lame warnings and leaving assert() alone?
> Sometimes, they remind me of something I had forgotten to implement
> or to clean up.

Sometimes they do that, however the fact that assert leaves its
argument unused is its major design feature. Anything you do to fool
the compiler may also fool the optimizer. If you're OK with that risk,
you should be OK with not defining NDEBUG to begin with.

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at