|
|
|
|
|
by mjschultz
4184 days ago
|
|
I'm referring to this code on the originally linked page [1] (you'll have to scroll back a bit because your header blocks the content). In the context of this thread, brghts states that this is dangerous because if you compile with -DNDEBUG the assert is optimized away. So if I copy that code with the assert statement, it will be optimized away and your code no longer performs the NULL check. This is bad. As you mention, beginners tend to copy code off the Internet and cause bugs. If you recognize this and claim to be teaching people you should not use bad practices in your example code. Period. If you don't want to muddy the waters with your custom debug macros, then you should still play it safe when checking return values the a beginner may simply copy and think is correct. [1]: http://c.learncodethehardway.org/book/krcritique.html#code--... |
|