N
Nick Keighley
If I read you correctly, it sounds like nowadays assert is the wrong
level of abstraction for checking against dereferenced NULL pointers,
I'm not sure I read that in what he said
due to operating system maturity. That sounds reasonable to me. Was
there any time when it was needed to provide this kind of context?
crashing is pretty traditional. The C library assumes you pass it the
right stuff. You put the asserts in *your* code.
I was under the impression that assert was for developers, not
computer users. My understanding is that assert is NDEBUGed out
before it gets to the computer user.
this is a fairly common practice but FAR FAR from being universal.
Many megabits have been ruthlessly expended on clc (and elsewhere)
arguing if assert()s should be NDEBUGed. That Microsoft's compilers do
this by default doesn't we have to imitate them.
If assert is being used as
communicating errors to users, that's a different can of worms. And
this was a topic covered in the other couple of threads I read on
assert.
assert() is a pretty crude instrement for communicating with users.
The user should never see an assert message. OTOH I don't want my
program running on with its fundamental assumptions left in tatters. I
tend to use my own assert-like macros that write to log files before
dieing. At least they can email me the logfile.
I'm curious, do you or any of the other coders around here have used
'assert' at all in your C code within the last year?
yes. In noddy tools. As preconditions in functions. As crude test
harnesses. But I tend to prefer my own assert-like thingies. So I
*know* which ones are left in the shippable version. That they write
to a log file. Preconditions might be left as assert() (though I
suppose those should be PRE_CONDITION or something).
Until I stumbled
across some assert thread looking for something else, I never
considered using assert in my code. Unless I know how to use 'assert'
right, I really don't want to use it at all.
I'm not sure ther eis a "right". Look up Design by Contract. assert()s
can be a cheap and cheerful way of asserting a functions's
preconditions. If you use assert()s as preconditions quite copiously
you'll be surprised how often you stumble into them.