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

Re: Interesting - [ A user's experiences with GCC-3.4 snapshots]

Thread Previous | Thread Next
Chip Salzenberg
September 16, 2003 18:24
Re: Interesting - [ A user's experiences with GCC-3.4 snapshots]
Message ID:
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. -               <>
"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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About