Hacker News new | past | comments | ask | show | jobs | submit login

I get that assert() is a macro, but how does that affect the scope of char *p that it "works" in one case and segfaults (as I'd expect) in the other?



OK -- I wasn't looking at this clearly. In case there are others like me:

  * 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 :P

I thought there was deeper magic, but it's really just programming flow, and knowing good practices re: assert() (or anything that has side effects).




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: