• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Awful function pointer conversion function template
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Awful function pointer conversion function template


  • Subject: Re: Awful function pointer conversion function template
  • From: Dmitry Markman <email@hidden>
  • Date: Sat, 19 Dec 2009 19:24:13 -0500

so basically you want to do the following

template <typename R>
struct FTypes {
    typedef R (*rt)(...);
    typedef R (*rt_void)();
};

template <typename R>
typename FTypes<R>::rt convert_ptr(typename FTypes<R>::rt_void src) {
    return reinterpret_cast<typename FTypes<R>::rt>(src);
}

is it correct? if so, I'm just curious, why do you need it?
 thanks


On Dec 18, 2009, at 9:15 AM, Dan Caugherty wrote:

Thank you very much!   (Nice catch!)

Cheers,
-- Dan C.

On Fri, Dec 18, 2009 at 4:49 AM, Jens Miltner <email@hidden> wrote:

Am 18.12.2009 um 04:17 schrieb Dan Caugherty:

Hey all --

This is really a C/C++ question, and it's giving me fits, since it's not obvious why there's a syntax error.

Now, I believe I have a legitimate reason for doing what I'm doing, so just trust me. Yes, the code below looks dangerous, but I have some function pointers in legacy code that I must deal with, so I'm trying to minimize the danger in this particular case with some modicum of type checking based on return type.

I'd like to write a quick function template to change a function pointer from type " return_type (*)(void) " to "return_type (*)(...)".  I thought this would work:

template <typename RetT>                            // zero-parameter case 
RetT (*convert_ptr(...)) ( RetT (*src)(void) ) {     // can't use variadic templates yet.. sigh....
   typedef RetT (*rt)(...);                   //wouldn't mind getting rid of this line somehow
  return reinterpret_cast<rt>(src);     //ERROR: "src" was not declared in this scope.
}

Why is gcc tripping on the last line?

I believe the template function declaration needs to be :

RetT (*convert_ptr ( RetT (*src)(void) ))(...) {     // can't use variadic templates yet.. sigh....

</jum>



Dmitry Markman


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Awful function pointer conversion function template (From: Dan Caugherty <email@hidden>)
 >Re: Awful function pointer conversion function template (From: Jens Miltner <email@hidden>)
 >Re: Awful function pointer conversion function template (From: Dan Caugherty <email@hidden>)

  • Prev by Date: Re: Why Is NSLog a No-Op?
  • Next by Date: NSLog a No-Op Probably Explained
  • Previous by thread: Re: Awful function pointer conversion function template
  • Next by thread: Syntax coloring for .inl files
  • Index(es):
    • Date
    • Thread