From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 87190 invoked by alias); 16 Mar 2017 21:46:21 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 87172 invoked by uid 89); 16 Mar 2017 21:46:20 -0000 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 Received: from ishtar.tlinx.org (HELO Ishtar.sc.tlinx.org) (173.164.175.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Mar 2017 21:46:19 +0000 Received: from [192.168.3.12] (Athenae [192.168.3.12]) by Ishtar.sc.tlinx.org (8.14.7/8.14.4/SuSE Linux 0.8) with ESMTP id v2GLkGuv056769 for ; Thu, 16 Mar 2017 14:46:18 -0700 Message-ID: <58CB07A8.9010401@tlinx.org> Date: Thu, 16 Mar 2017 21:46:00 -0000 From: L A Walsh User-Agent: Thunderbird MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Re: free() and implicit conversion to a function pointer References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00180.txt.bz2 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