It's not. printf will fail for all sorts of reasons like ENOSPC.
-
-
Replying to @RichFelker @johnregehr
The programmer is making an assumption about the whole system, which is a fine one if you don't care about the behavior of the program when that assumption is false.
1 reply 0 retweets 0 likes -
Replying to @samth @johnregehr
You're free to disagree, but in teaching the language and its idioms, this should be explained as erroneous use. assert documents something that supposedly can't happen; it doesn't test for unwanted runtime conditions.
2 replies 0 retweets 0 likes -
If adding -DNDEBUG would make the program misbehave under certain conditions, you're misusing assert().
1 reply 0 retweets 0 likes -
Replying to @RichFelker @samth
not sure I like this as an operational definition, since a buggy program + -DNDEBUG will indeed misbehave, instead of crashing cleanly
2 replies 0 retweets 1 like -
Replying to @johnregehr @samth
Indeed, it should be understood in a context of intent and a (probably false) assumption that the program is not buggy.
1 reply 0 retweets 2 likes -
Replying to @RichFelker @samth
now I'm happy with your definition again! but I'm also generally OK with a minor abuse such as the one Sam is suggesting, which is really a shorthand for something pretty complicated about the whole system...
1 reply 0 retweets 0 likes -
Replying to @johnregehr @RichFelker
Similarly, asserting that input reads as a positive integer is fine if it's a claim that the intended scope of invariants includes the user (fine in a script for just my use, bad in a public website).
1 reply 0 retweets 0 likes -
in the C context, I'm not sure that's fine if the assert is the only thing standing between the input and UB-induced launch-the-missiles. "error and abort if this is wrong" is very different than something that disappears under -DNDEBUG
1 reply 0 retweets 1 like -
in extremely informal settings I'm fine with this usage of assert(), which requires that -DNDEBUG is never used, but never if the code might be reused somewhere else.
3 replies 0 retweets 0 likes
It's still just a bad habit to get in. You should use language idioms right even in throwaway code.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.