Hi,

On 04/07/2022 10:19, NRK wrote:
Hi Laslo,

On Sun, Jun 26, 2022 at 11:16:32PM +0200, Laslo Hunhold wrote:
come on, it is general knowledge that free() accepts NULL arguments.

I don't think that's a true. If it were general knowledge then we
wouldn't see the pattern of `if (ptr) free(ptr)` in the code to begin
with.

And overall, I don't believe most "resource-release" functions have this
behavior. For example fclose, closedir, munmap etc don't accept NULL
arg. So `free` is more of an exception to the general knowledge.

Just wanted to share my opinion: defining what's "general knowledge" can prove to be extremely non trivial.

I'd say that if the language spec says so, the manpage says so and it is known that compilers obey to the spec (as they should), the feature should be deemed well defined and thus used.

Some people do not keep up with the various changes in a language and may get stuck on an older version (which for example does not behave this way). But this is not, IMHO, a good reason to not evolve the code (especially when it gets simpler)

Cheers,


--
Antonio Quartulli

Reply via email to