Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!mit.eternal-september.org!.POSTED!not-for-mail From: Richard Newsgroups: comp.lang.c Subject: Re: free a pointer and have it point to NULL Date: Tue, 29 Apr 2014 13:14:11 +0200 Organization: http://www.ieee.org/ Lines: 31 Message-ID: <87fvkw75h8.fsf@gmail.com> References: <639a5283-8e4b-4f9a-aa7f-ef2c88174768@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mit.eternal-september.org; posting-host="a0e0bcceb01a4703df7b4a89dec2423c"; logging-data="6442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LYXVIb9Qg7UdJgibtHZuA1wFqL3YYNrs=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:MzDzcTjWgHm1WWn6JMOUB6aemTk= sha1:kHrrd9kex4fWZa0UkxVfBgbMPCw= Xref: csiph.com comp.lang.c:43812 Johannes Bauer writes: > On 22.04.2014 23:37, Keith Thompson wrote: >> G G writes: >>> memory allocated on the heap once freed should the pointer be assigned NULL? >> >> Maybe. >> >> After free(ptr), the value of ptr is *indeterminate*, meaning that any >> attempt to refer to its value has undefined behavior. > > Woo, really? I find that rather surprising. Does this mean that free() > specifically is a special case or was this just a writing error on your > part? If free behaved like all other functions, the value of ptr would > be well defined after the free (to be the same value as before the free, > since pointers are call-by-value). > > Defererencing that pointer after a free has obviously indeterminate > consequences, but is also the pointer *value* indeterminate? > > Regards, > Johannes Of course it isnt. The pointer value cant be changed since the parameter is a void * : VALUE. The free() function can not alter the value in the pointer variable used to provide that void * value to the function. -- "Avoid hyperbole at all costs, its the most destructive argument on the planet" - Mark McIntyre in comp.lang.c