4 ms·
> The first block of code seems more readable to me than the second. I'm used to seeing the first; it's idiomatic C. The benefits of the macro (IMO) aren't obv
by theseoafs 13y ago
> The first block of code seems more readable to me than the second. I'm used to seeing the first; it's idiomatic C.
The benefits of the macro (IMO) aren't obvious from the example I gave. Like I said, I'm currently working on a personal project where macros have been the saving grace. Attaching a conditional return to every individual statement was making my code extremely hard to maintain (even for myself, who wrote it) -- wrapping common error cases in a macro made everything a whole lot simpler, and allowed me to work on my algorithms at a high level without having to run my eyes over the same error-checking `if` statements a million times.
> I don't understand why it says "do ... while (0)" in the macro, for instance.
It's normal for many macros, so that you can use them like normal statements.
> In your example, you're just going to leave the file open and the string allocated?
I sort of just made that example up off the top of my head -- you're right about the memory leak.