Boost logo

Boost :

From: Alan Bellingham (alan_at_[hidden])
Date: 2004-01-05 06:25:07


(Hartmut Kaiser:

>Dan W. wrote:
>
>> //file: verify.hpp
>> #ifndef VERIFY_HPP
>> #define VERIFY_HPP
>>
>> #ifdef _DEBUG
>> # define verify(x) do{if(!((x)))asm int 3;}while(0)
>> #else
>> # define verify(x) (void)(0)
>> #endif
>>
>> /*
>>
>> // Usage example:
>> #include "verify.hpp"
>> #include <stdio.h>
>> char first_char( char const * s )
>> {
>> verify( s && ::strlen(s) ); //<-stops right on it ;-)
>> return s[0];
>> }
>> // Cheers!
>> // dan
>>
>> */
>>
>> #endif
>
>That's more or less the same as contained in almost every <assert.h> header.
>So what's new with your suggestion?

Not only is it very similar to the assert macro, but it _isn't_
consistent with the VERIFY macro offered by Microsoft in MFC.

In MFC, VERIFY(x) expands to (void)(x) in release mode - meaning that
the expression is always evaluated, unlike the ASSERT macro which
disappears in release mode. This distinction is useful because sometimes
you do want the expression evaluated in order to achieve the side
effects.

Oh, I'd also strongly recommend _not_ introducing new macros with
lowercase names - they're much less likely to cause naming clashes.

Alan

-- 
Alan Bellingham

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