Of course we all have brain farts now and then, but there's no way this code should survive a second, let alone a third reading.
Or am I just being conceited?
Of course we all have brain farts now and then, but there's no way this code should survive a second, let alone a third reading.
Or am I just being conceited?
The biggest surprise for me is that this error survived more than one attempt to remove it...
That said, like the previous comments, if someone had seriously looked for this issue, you'd have hoped they'd have found this pretty quickly.
But it could easily be somewhere creepy and random, and the side-effects a bit hard to spot, making it harder to find.
(Which, of course, is why you should always put all of this stuff in `main' ;)
I'm not arguing that asserts should stick around forever, but it's obvious that there's at least an occasional need for something like assert in production code, and so it's not as straightforward as you suggest for someone who has never been told to jump to the correct conclusion.
* the scope of *p is only global. My comment re: scope is just Wrong.
* there is never a call to someinitialization() *execpt* via the assert. If no assert() is called, the Bad Value prevails; if the assert() is called, it resets *p.
I feel a bit foolish, but found it easy to misread this at first glance. If anybody else didn't get it initially, hopefully this helps :PI thought there was deeper magic, but it's really just programming flow, and knowing good practices re: assert() (or anything that has side effects).