Passing around a list of differently typed functions
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 23 11:35:12 PDT 2014
On Mon, 23 Jun 2014 14:30:12 -0400, Ali Çehreli <acehreli at yahoo.com> wrote:
> On 06/22/2014 11:32 PM, FreeSlave wrote:> On Monday, 23 June 2014 at
> 01:16:49 UTC, Evan Davis wrote:
> >> As the subject says, I would like to pass around an array of
> >> functions. The trick is, that the functions have different type
> >> signatures. Is there a way to put the two functions
> >>
> >> int foo(int a, int b);
> >> bool bar(bool a, bool b);
> >>
> >> into one array, that I can pass around and cast as necessary?
> >>
> >> Thanks, Evan
> >
> > You can pass them as pointers, for example cast to void*. But you
> still
> > need correct signature to cast pointer to actual type before call
> function.
>
> In C and C++, void* is for data pointers only. As function pointers are
> a different kind of beast, casting to and from void* is undefined
> behavior. (Note: It works on all common platforms.)
Wow, really? That is strange.
> I wonder whether D has any decision on that.
I would hope it's defined. A pointer is a pointer.
-Steve
More information about the Digitalmars-d-learn
mailing list