ANSI assert

John R. Levine johnl at esegue.segue.boston.ma.us
Sun Sep 9 12:52:49 AEST 1990


In article <1428 at proto.COM> you write:
>  assert(i++ < limit);

Asserts with side effects have always been a bad idea, as is practically
any macro call with side effects.  Every implementation of assert that I
have ever seen throws away the argument to assert without evaluating it if
NDEBUG is defined.  You have my condolences if this breaks your programs,
but even before ANSI such programs had major portability problems.  If you
ever plan to use a compiler other than the one you're using now, you'd
better plan to fix your code.

This is a famous problem by now, I know lots of programs that couldn't be
shipped with NDEBUG set exactly because there were side effects in the
asserts.  (I think this is an argument for better programmer education
rather than fudging the language to the tastes of sloppy programmers.)

Regards,
John Levine, johnl at esegue.segue.boston.ma.us, {spdcc|ima|world}!esegue!johnl



More information about the Comp.std.c mailing list