Forgot your password?
typodupeerror

Comment Re:printf (Score 1) 425

That example is a WRONG use of assert -- you're using assert() as a poor-man's exception.

The right way to code that is

if (foo == null) { // bad state
    return some_error_value;
}
assert(foo != null); // do something which presumes that foo is not null...

Writing an assert in your code is the statement that you have examined your code and believe you have proved that it is _impossible_ under any circumstances, for the assertion to be false -- not bad user input, not a bad call from client code, there are no possible bad conditions you haven't already handled, nothing.

Thus if an assertion evaluates to false, the impossible has just happened. Black is white, gravity points upwards, your computer is an iguana. Your program has (in effect) already crashed, but the world hasn't noticed yet.

So, what do _you_ want to do at this exciting point, in production code? Just carry on with your fingers crossed and see what happens next?

Slashdot Top Deals

"Mr. Spock succumbs to a powerful mating urge and nearly kills Captain Kirk." -- TV Guide, describing the Star Trek episode _Amok_Time_

Working...