ANSI assert

Jim Patterson jimp at cognos.UUCP
Fri Sep 14 04:58:19 AEST 1990


In article <1990Sep8.164857.2930 at jarvis.csri.toronto.edu> norvell at csri.toronto.edu (Theo Norvell) writes:
>As has been pointed out, you may write your own assert macro.  May I
>suggest
>
>#define assert_and_do(x) ((x) || assert(0))

There's a slight problem with this. While it will work, it will print
a rather misleading message with many ANSI implementations of assert (which
print out the failing condition). For example, you might see:

		Failed assertion (0) at line 117 of myfile.c

when what you want to see is:

		Failed assertion (x_init - x*x < EPS) at line 117 of myfile.c

It would be better, though more work and potentially less portable, to copy 
and modify the definition of assert().
-- 
Jim Patterson                              Cognos Incorporated
UUCP:uunet!mitel!sce!cognos!jimp           P.O. BOX 9707    
PHONE:(613)738-1440                        3755 Riverside Drive
                                           Ottawa, Ont  K1G 3Z4



More information about the Comp.std.c mailing list