develooper Front page | perl.perl5.porters | Postings from September 2003

Re: Interesting - [drow@mvista.com: A user's experiences with GCC-3.4 snapshots]

Thread Previous | Thread Next
From:
Chip Salzenberg
Date:
September 16, 2003 18:24
Subject:
Re: Interesting - [drow@mvista.com: A user's experiences with GCC-3.4 snapshots]
Message ID:
20030917012523.GD15294@perlsupport.com
According to Enache Adrian:
> Just a cast to void* 'if ((void*)&func) ...' will probably get this right --

Unfortunately not.  You must cast, but void* isn't a portable choice.

Function pointers are not guaranteed castable to any data pointer
type, not even void*.  They're guaranteed castable among each other,
though (as long as you get them back to their original types before
calling through them (which we aren't doing anyway)).

So this should be portable:

   typedef void VFUNC();
   if ((VFUNC*)func != (VFUNC*)main) { ... }

PS: Note that the "&" before a function name is entirely unnecessary.
PPS: I like to typedef functions, not function pointers, so that pointer
     types are still spelled with a "*".
-- 
Chip Salzenberg               - a.k.a. -               <chip@pobox.com>
"I wanted to play hopscotch with the impenetrable mystery of existence,
    but he stepped in a wormhole and had to go in early."  // MST3K

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About