2 ms·
The shortest code you can get away with is not always the best. If the parameter is a structure (which I think it is here, behind the void pointer), it's a good
by asveikau 10y ago
The shortest code you can get away with is not always the best. If the parameter is a structure (which I think it is here, behind the void pointer), it's a good idea to give it its own free function in case later you add additional struct members that will need freeing/cleanup in the same place. (Bonus points if it appears in roughly the same place this thing is malloc'd)
I would have been even more explicit and added a cast to the expected structure pointer type. Entirely useless, except to the human reader.
- userbinator 10y agoThat sounds like premature generalisation to me. I'd say use a separate free function when it needs one, which is not the case yet (and might never be.)
- asveikau 10y agoCall it an overreaction to a past project in which a predecessor scattered free calls over several uses, then I had to add fields. I don't mind adding 1 useless function per complex type if it saves me those headaches even a small minority of the time, or for the next maintainer. Opinions may differ, but that's me.
- gpvos 10y agoI think this is more of a maintainability/readability case. Your suggestion sounds like premature optimization to me.