4 ms·
I find the comma useful in deletion scenarios. For example, rather than just "free(x)" or "delete x" (after which the variable is undefined and can't be used a
by makecheck 15y ago
I find the comma useful in deletion scenarios. For example, rather than just "free(x)" or "delete x" (after which the variable is undefined and can't be used anyway), I like to use the comma to add a NULL assignment. So, "free(x), x = NULL". It doesn't really need to be that way, but it's nice for avoiding random behavior in case the variable is referenced later; and the chain on one line makes it unlikely that the 2nd part will be forgotten.
- andrewcooke 15y agowhy don't you use the semicolon? the comma is only adding something more if you're using the final value.
- makecheck 15y agoIt would hardly ever matter, that's true. But I can certainly contrive something that would require it, such as: if (something) f(); else delete x, x = NULL; Of course, I don't personally use "else" without a block, so it's just an example; I'm not suggesting it's a good idea.