[prog] Bug!!

Jimen Ching jching at flex.com
Mon Mar 3 00:19:36 EST 2003


On Sun, 2 Mar 2003, Sachin wrote:
>10 bytes or pow(10,100) bytes , coudn't the free function assign a NULL
>to the pointer to memory position it freed.Why should it be left as
>undefined behaviour?

There isn't really much benefit except to new C programmers that might
fall into this trap.  But once you learn it, you most likely won't make
the same mistake.  ;-)  Of course, if performance is not an issue, one can
always create a new heap API.  Create your own free() function which takes
a pointer to pointer and assign a NULL before returning.  This is a
feature of C.  The designers of the language specifically allow the
programmer to decide what is important.  Unlike other langauges, which
force a paradigm on its programmers, C allows you to do what is most
convenient at the moment.  Sorry for the small rant.  ;-)

I'm not sure if you've already read it.  But the C FAQ is a very good
reference for new programmers.

	http://www.faqs.org/faqs/C-faq/

Look at the non-abridged version by Steve Summit.  When I was starting
out, I've avoided many pitfalls after reading this document.

--jc
-- 
Jimen Ching (WH6BRR)      jching at flex.com     wh6brr at uhm.ampr.org


More information about the Programming mailing list