delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/03/17/00:53:06

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
q=dns; s=default; b=STljE9xmsgskWJ+RDZzl/VbaN0Do+tPCiU2RdQnVhnr
HtLiXAdpVPWYpPbGd9GKyAxigsOjH2vtAAqz/WQc4AqShY3ZdeD/FXtLKJZAO+p6
vJSxorfI6sPzME/bTuxPuKisF1EQQsf23mhJgWJc/S+W7RjbOsi/BPt3vxIFpXe4
=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
s=default; bh=tfEsJKp2UH9GoC9js1KQ8x/A65I=; b=SFGFfvIuNxk3sTYRD
BHxB1miF6d2pEzRSrzcfMg0X8pjXTe455qnS5z5XpOSC8D7Xybc/SkxSKTkqGqaW
T7CTimeu7kXWnpYJ+qNjiAcy3XpcRbZZDwp3WhAKLK5n55bEXmE2m9N3lyJfCDg8
XGbfpVegLce8J2Cbgi3I0w2USY=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_50,GIT_PATCH_2,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=subj, harvard, Harvard, incommensurable
X-HELO: Ishtar.sc.tlinx.org
Message-ID: <58CB07A8.9010401@tlinx.org>
Date: Thu, 16 Mar 2017 14:46:16 -0700
From: L A Walsh <cygwin AT tlinx DOT org>
User-Agent: Thunderbird
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: free() and implicit conversion to a function pointer
References: <c5af0608-17c4-2270-dbba-c3b704c9226e AT t-online DOT de> <f76885f4-f99f-dc50-2a19-cb892a62db7e AT t-online DOT de>
In-Reply-To: <f76885f4-f99f-dc50-2a19-cb892a62db7e@t-online.de>
X-IsSubscribed: yes

Going by subj and talk below, this is a bit confusing...

But it looks like you are testing 'free' for a value?

Isn't standard 'free' declared to take 1 arg and
return void?

If you aren't talking standard 'free()', then
nevermind...


Hans-Bernhard Bröker wrote:
> [Sorry, forgot to reply-all...]
>
> Am 15.03.2017 um 23:48 schrieb Jeffrey Walton:
>
>> Since Coverity is
>> complaining about an implicit conversion, maybe the following will
>> help to avoid the implicit part (and sidestep the finding):
>>
>>     if (free != NULL)
>>         break;
>>
>> Or perhaps:
>>
>>     if ((void*)free != NULL)
>>         break;
>
> Even setting aside that the latter should of course have been
>
>      if ((void*)free == NULL)
>          break;
>
> those are both worse than the original code.  (void *) is _not_ 
> suitable for use with function pointers.  Neither is NULL in the 
> general case, because it may very well be ((void *)0).
>
> The reason this is wrong is that C by design treats data and functions 
> as living in separate realms, i.e. its virtual machine has a Harvard 
> architecture.  One of the consequences of this is that pointers to 
> functions and pointers to data are incommensurable, i.e. any and all 
> conversions or comparisons across this divide are wrong.  (void *) are 
> compatible to all data pointers, but not to function pointers.
>
> 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 what language?

It's not a C-function nor a C function pointer.



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019