🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Function pointer casting

#821
From: MW Ron
Date: Mon, 02 Jun 2003 16:01
48 lines
2867 bytes
In article <3EDB6B20.2000804@lgl.kos.net>,
 Edward Chew <ekc-noreply@lgl.kos.net> wrote:

>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?

You might still get away with this in C, and relaxed pointer rules did 
you try it?  

Ron

-- 
  Get printed CodeWarrior Documentation (limited selection) 
     And all the latest versions of CodeWarrior Manuals

http://www.metrowerks.com/MW/Support/dev_resources/default.htm

Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com
Technical Details
Message-ID: <mwron-15BF62.12013802062003@enews.newsguy.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!pln-e!spln!dex!extra.newsguy.com!newsp.newsguy.com!mwron
References: <3ED6734A.6080600@lgl.kos.net> <mwron-5286CB.09413702062003@enews.newsguy.com> <3EDB6B20.2000804@lgl.kos.net>

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 09:20:16 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!pln-e!spln!dex!extra.newsguy.com!newsp.newsguy.com!mwron
From: MW Ron <mwron@metrowerks.com>
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac
Subject: Re: Function pointer casting
Date: Mon, 02 Jun 2003 12:01:38 -0400
Organization: Metrowerks
Lines: 48
Message-ID: <mwron-15BF62.12013802062003@enews.newsguy.com>
References: <3ED6734A.6080600@lgl.kos.net> <mwron-5286CB.09413702062003@enews.newsguy.com> <3EDB6B20.2000804@lgl.kos.net>
NNTP-Posting-Host: p-867.newsdawg.com
User-Agent: MT-NewsWatcher/3.2 (PPC Mac OS X)
X-Face: )mY~XFHLw)UOW!W#[Ljvxq6Ja7(g'#F0-g*&puNxR8hEJkd@Oue/70^.)I78\
        (%a%&Id211u"l/t.llWo/M|?15XUlx9!IGkdWiEmcasiyg"k;Q9[~XuE+`t2"*n(>nmm
        @L/q,TjMd5+H{gASEPDR^$