News for hackers. Stuff that matters.
Re:C Programming Guidelines by asveikau on Wednesday September 02, 2015 @12:48AM (#10157488)
If you want to get nitpicky, you could also say there is performance cost to jumping into libc.so for free, then having it do a null check for you, then jump back to your code. Maybe that's worse than doing the null check more "locally".

But I do make a point whenever I'm writing C, if I write a cleanup function for a new type of struct or whatever, cleaning up null is always a no-op. It just makes life slightly less tedious. Having to remember which functions do this and which don't, I'll admit, is annoying.

Re:C Programming Guidelines by lucozade on Wednesday September 02, 2015 @09:54AM (#10159118)
I would venture that, if a few (essentially no-op) .so function calls are likely to affect performance to a point that you care, allocating and de-allocating heap memory under those same conditions might be a bit more of an issue.

Depends on the detail of the use case of course, but assuming that NULL cleanup is more the exception than the rule this is definitely a case of profile it first for me.

Re:C Programming Guidelines by caf on Wednesday September 02, 2015 @02:47AM (#10157763)
On the other hand, replicating

  if (p != NULL)
checks across your codebase will have a higher I$ footprint than sharing a single check inside free(), so the overall performance impact could easily be positive.