Deutsch English Français Italiano |
<vlu4fk$mc06$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: So You Think You Can Const? Date: Sat, 11 Jan 2025 10:58:44 -0500 Organization: A noiseless patient Spider Lines: 21 Message-ID: <vlu4fk$mc06$1@dont-email.me> References: <vljvh3$27msl$1@dont-email.me> <vlma9m$2s5e5$1@dont-email.me> <vlolsf$3cnll$4@dont-email.me> <vlqd9p$3s4ai$2@dont-email.me> <vlqstb$3uk5j$1@dont-email.me> <87v7umpkfv.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 11 Jan 2025 16:58:45 +0100 (CET) Injection-Info: dont-email.me; posting-host="b612924d5bfdf050c235cb51d03338be"; logging-data="733190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WP8CqSHIdy5cUK2WL1CKzXpJ1ARQkjbc=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:6n/DAUD0Wdv+iQ+7JribRoaXUsE= In-Reply-To: <87v7umpkfv.fsf@nosuchdomain.example.com> Content-Language: en-US Bytes: 2316 On 1/10/25 13:56, Keith Thompson wrote: > David Brown <david.brown@hesbynett.no> writes: > [...] >> If you want a better signature for "free", then I would suggest "void >> free(void ** p)" - that (to me) more naturally shows that the function >> is freeing the pointer, while also greatly reducing the "use after >> free" errors in C code by turning them into "dereferencing a null >> pointer" errors which are more easily caught by many OS's. > > I'm not sure that would work. A void** argument means you need to pass > a pointer to a void* object. If you've assigned the converted result of > malloc() to, say, an int* object, you don't have a void* object. (int* > and void* might not even have the same representation). Correct. As a result, that interface would, in principle, require storing the pointer in a void* object so that it's address could be passed to free(). In many contexts, that would encourage saving the original void* value returned by malloc() for passing to free(), while creating a second pointer for actually using the allocated memory.