Please reread your first paragraph.
Then realize why:
if (ptr != NULL)
is superior to
if (ptr)
At this point I should slink off with my tail between my legs,
but I do want to defend those of us who screwed this up by saying
that the context of this thread made me assume, without really
thinking about it, that the incident being explained would be
more relevent to the discussion that it turns out to be.
We're conditioned to assume, to gleen the meaning of things by
their context. Even though a native English speaker has an
everage vocabulary of 360,000 words, we don't know exactly what
they all mean instantly: we have to guess from context. We
compose sentences in the same way, rendering out-of-context
quotations meaningless, or even sometimes seeming to say the
opposite of what was meant. Similarly, we often don't easily
recognize familiar faces of people we know from one part of our
life if they pop up in another.
We did not get to see the code surrounding the error, which may
well have made it an obvious mistake, e.g.:
My foolish, working-code altering colleague changes this:
char *ptr = malloc(500);
if (ptr == NULL) {
return EXIT_FAILURE;
}
into this:
char *ptr = malloc(500);
if (ptr) {
return EXIT_FAILURE;
}
My guess is that close to 100% of the readers here would've
spotted *that* code defect.
The post had a similar context-subversive effect as the old joke:
"If a passenger airplane crashes exactly on the border between
Canada and the USA, where do they bury the survivors?"
In any case, I applaud the author. It was a good trick, and boy
is my face red. Lucky for you all, I'm not working on your
project. ;-)