On 12/26/2009 10:27 AM,
wrote:
> On Dec 26, 10:31 pm, Richard<rgrd...@gmail.com> wrote:
>[...]
>> It is. asserts suck and are the sign of sloppy programmers who only use
>> them to appear to be concerned about reliability. An assert condition
>> should simply not occur.
>
> I don't agree that assert condition should simply not occur.
> such as, assert NULL pointer, I think it can occur at high
> possibility.
The claim that "asserts suck" sucks, but their purpose must
be properly understood: They are useful to the programmer, but
not to the end user. They can alert the programmer to programming
errors, but are not good for things like validating user input.
Since an unsuccessful assert() terminates the program (unless
you're doing tricky things with SIGABRT), an assert() that fires
with "high probability" means the program dies with that same
high probability -- which indicates that the program is not very
useful, because it keeps dying!
> So, gcc -NDEBUG -g *.c *.c -o * will work without assert?
The command line as shown will probably not work at all.
Changing it to something like "gcc -DNDEBUG -g *.c" will cause
the NDEBUG macro to be defined at the start of each .c file's
compilation. If it's still defined when <assert.h> is included
(that is, if you don't #undef it first), the assert() calls in
that file will expand to no-ops that have no effect on the
program's execution.
--
Eric Sosman
lid