🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #820

Re: Function pointer casting

#820
From: Edward Chew
Date: Mon, 02 Jun 2003 15:20
34 lines
2671 bytes
MW Ron wrote:
> In article <3ED6734A.6080600@lgl.kos.net>,
>  Edward Chew <ekc-noreply@lgl.kos.net> wrote:
> 
> 
>>After upgrading to CW 8, I notice the compiler no longer allows implicit 
>>casting from function pointers (e.g. "int (*)()") to void*.  Is this a 
>>bug or some weird C/C++ standards compliance thing?  For now, it seems 
>>happy if I write static_cast<void*>(fn).
> 
> 
> This is not legal implicitly or explicitly but we allow the explicit 
> cast because this is common for legacy code.  

Interesting.  I wonder why it would be illegal, and what the legal 
alternative would be?  I ran into this problem when weak-linking to 
certain CFM libraries and testing to see if they are available.  In 
Apple literature, they recommend testing the init routine like this:

     if(LibraryInitFunction == kUnresolvedCFragSymbolAddress)
         reportLibraryUnavailable();

This will immediately cause a type mismatch error at compile time in 
Codewarrior 8.  Figuring a pointer is a pointer, I rewrote this as:

     if(static_cast<void*>(LibraryInitFunction) ==
        static_cast<void*>(kUnresolvedCFragSymbolAddress)
        )
          reportLibraryUnavailable();

This seems to work fine, but now I am told it is illegal as well.  What 
would be the proper test in that case?

Edward K. Chew
Technical Details
Message-ID: <3EDB6B20.2000804@lgl.kos.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!209.242.76.12.MISMATCH!newsfeed!news.kos.net!not-for-mail
References: <3ED6734A.6080600@lgl.kos.net> <mwron-5286CB.09413702062003@enews.newsguy.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bcce,9c35d45628066e65
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,9c35d45628066e65
X-Google-Attributes: gidf635e,public
X-Google-ArrivalTime: 2003-06-02 08:20:17 PST
Message-ID: <3EDB6B20.2000804@lgl.kos.net>
Date: Mon, 02 Jun 2003 11:20:00 -0400
From: Edward Chew <ekc-noreply@lgl.kos.net>
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac
Subject: Re: Function pointer casting
References: <3ED6734A.6080600@lgl.kos.net> <mwron-5286CB.09413702062003@enews.newsguy.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Original-NNTP-Posting-Host: 216.185.95.133
X-Original-Trace: 2 Jun 2003 11:18:57 -0400, 216.185.95.133
Organization: Kingston Online Services
Lines: 35
NNTP-Posting-Host: apollo.kos.net
X-Trace: newsfeed 1054566840 199.246.2.51 (2 Jun 2003 10:14:00 -0500)
X-Original-NNTP-Posting-Host: 199.246.2.51
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!209.242.76.12.MISMATCH!newsfeed!news.kos.net!not-for-mail