free() and implicit conversion to a function pointer

Corinna Vinschen corinna-cygwin@cygwin.com
Fri Mar 17 08:30:00 GMT 2017


On Mar 17 00:49, Hans-Bernhard Bröker wrote:
> Am 16.03.2017 um 22:46 schrieb L A Walsh:
> > Going by subj and talk below, this is a bit confusing...
> > 
> > But it looks like you are testing 'free' for a value?
> 
> Not really.  The idea is to test free for _exixtence_.  Which only makes
> sense in case of weak symbol support getting involved.  In other situations,
> there could not possibly be a need for a run-time if() test, because surely
> the code could know at build time whether free() exists or not.
> 
> > Isn't standard 'free' declared to take 1 arg and
> > return void?
> 
> Yes.  But since the code in question doesn't actually _call_ free, that's
> both irrelevant.
> 
> > If you aren't talking standard 'free()', then
> > nevermind...
> 
> We are talking standard free.  More to the point, we're discussing newlib,
> the package that actually implements free() for cygwin.
> 
> > > The only code that might actually be a slight bit better than the given
> > > 
> > >     if (! free)
> > > 
> > > would be
> > > 
> > >     if (0 != free)
> > > 
> > > The function designator `free' auto-decays into a function pointer,
> > > which is compared to a null pointer constant: 0.  The ! operator does
> > > that same thing implicitly, but is fully equivalent to it.
> > ---
> > Free autodecays to a function pointer?
> 
> In the use case at hand: yes, it does.
> 
> > In what language?
> 
> Standard C.

Wasn't that supposed to go to the newlib list where this has been
discussed originally?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20170317/ad9c2c89/attachment.sig>


More information about the Cygwin mailing list