[antlr-interest] Updates for release 3.2 of the C Target

David-Sarah Hopwood david-sarah at jacaranda.org
Wed Sep 23 23:32:56 PDT 2009


Jim Idle wrote:
> On Sep 23, 2009, at 5:31 PM, David-Sarah Hopwood
> <david-sarah at jacaranda.org> wrote:
> 
>> "free(NULL)" is defined to be a no-op by the C standard. A libc
>> implementation that got this wrong would be badly broken, and AFAIK all
>> the commonly used platforms get it right.
> 
> Some platforms define this to be undefined though. Remember there are
> lots if embedded systems that use this. Hence the qualification. I think
> it would have been better to define free(NULL) as safe myself but early
> Lib C would crash if you did this and I think it was C++ that first took
> a stand?

Perhaps very early libc's, but it is defined to be a no-op in C89.
Note that in a system with memory protection, if it does crash then it
will do so immediately with a segfault (at which point you should
complain vigorously to the libc provider).

I do realise that not all systems have memory protection -- but at the
end of the day you can't hope to defend against bugs in a C implementation
in application code, and this behaviour for free(NULL) is not an obscure
thing to rely on.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list