Dizio at Dizio at
Thu Mar 12 08:55:42 AEST 1987

I found this macro for assert in <assert.h> under ULTRIX 1.2
under the SYSTEM_FIVE #ifdef

#define assert(EX) if (EX) ; else _assert("EX", __FILE__, __LINE__)

It fails when given given an expression containing '"'.  
  eg. assert ((fp = fopen("filename","r")) != NULL)

My question is this.  Is this a proper implementation of this
functionality.  I'm not sure why it wants to pass the EX to
_assert except perhaps to print the expression out,  but in reality
the line number and file name is all I ever need to know.

This is especially true since assert is mainly a debugging tool
and not anything I would put into release software.  Mainly
because one generally would want more control over the action
to take, and the message printed to the user.

The non-system define is

#define _assert(ex) \
	{if (!(ex)) {\
		fprintf(stderr,"Assertion failed: file %s, line %d\n",\
			__FILE__, __LINE__);\

and of coarse if has no problem with any valid expression.

I realize this is a minor point as I could simply write my own macro,
but I just wondered if the proposed standard has specified whether
any valid expression should be able to be used inside the assert,
Or only expressions which don't contain '"'.


More information about the Comp.lang.c mailing list