Article View: comp.std.c
Article #4493Re: Should free() take a pointer to const argument?
From: John Robert Williams
Date: Sat, 16 Dec 1995 19:09
Date: Sat, 16 Dec 1995 19:09
23 lines
1404 bytes
1404 bytes
Jerry Coffin (jcoffin@rmii.com) wrote: > Lawrence Kirby <fred@genesis.demon.co.uk> wrote: > >Is there any good reason why free shouldn't be declared as: > >void free(const void *ptr); > >in the standard? I don't believe there is any notion of altering a variable > >when it is destroyed - after all const auto variables are destroyed just like > >any other auto variable when they go out of scope. > A good point. Even if the library knows it can cast away the const, it > allows you to pass a pointer to a const object without an explicit cast. This seems to me to miss the point of "const", which is really a promise on the part of a function writer that the object pointed to by a pointer will survive the function call intact. I don't think a function can make that claim if it destroys the object! -- #define REAL_NAME "John Williams" #define E_MAIL "johnw@jove.acs.unt.edu" #define HOMEPAGE "http://www.unt.edu/~johnw"
Technical Details
Message-ID:
<4av5ge$obs@hermes.acs.unt.edu>Path:
arc1-ca.pugleaf.net!news.unt.edu!jove!johnwReferences:
<818626119snz@genesis.demon.co.uk> <4am3dn$6s9@natasha.rmii.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.unt.edu!jove!johnw From: johnw@jove.acs.unt.edu (John Robert Williams) Newsgroups: comp.std.c Subject: Re: Should free() take a pointer to const argument? Date: 16 Dec 1995 19:09:02 GMT Organization: University of North Texas Message-ID: <4av5ge$obs@hermes.acs.unt.edu> References: <818626119snz@genesis.demon.co.uk> <4am3dn$6s9@natasha.rmii.com> NNTP-Posting-Host: jove.acs.unt.edu X-Newsreader: TIN [version 1.2 PL2]