Ticket #105 (NULL checks)
Joshua Juran
jjuran at gmail.com
Wed Dec 31 20:20:09 UTC 2008
On Dec 31, 2008, at 8:57 AM, kjstol wrote:
> On Wed, Dec 31, 2008 at 5:03 PM, Mark Glines <mark at glines.org> wrote:
>
> > I'm pretty sure assert() is a C library function.
>
> I think it's a C #define'd macro, not a function, which is not
> expanded if you set the right debug #define
> (don't know details by heart).
C's assert() must be implemented as a macro, so the failure report
can make use of the string containing the assertion itself (see
'#cond' below) as well as __FILE__ and __LINE__.
Macros are always expanded, to whatever you define them to. The
trick is that you can define them differently based on other macros
set by the build manager.
I defined my own ASSERT() macro (which has less surprising semantics
than assert() and helps avoid warnings):
#if TARGET_CONFIG_DEBUGGING
#define ASSERT( cond ) if ( !(cond) )
ReportAssertionFailureAndAbort( #cond, __FILE__, __LINE__ ); else 0
#else
#define ASSERT( cond ) if ( 0 ) (void) !(cond); else 0
#endif
If cond is known to be non-NULL, then the debugging assertion will be
stripped out in optimization just as handily as the non-debug one.
Josh
More information about the parrot-dev
mailing list