Metrowerks compiler issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Metrowerks compiler issue

463 Views
cw_Potz
Contributor I

Hello all,

 

I have 2 functions, both are identical except that one function is a template function. When I send the functions as function_pointer arguments to some other function, Metrowerks compiler complains for the template function.

 

template <typename T>
static void
call_stub (void *argument)
{

    ...........

    ..............
}

static void
call_stub_ (void *argument)
{

    ...........

    ..............

}

 

void register_callback ( (void (*)())(&call_stub<T>) )  ---- Gives error

void register_callback ( (void (*)())(&call_stub_) )      ---- Works fine.

 

Error Description:

Illegal explicit conversion from 'void' to 'void (*)()'.

 

Am I missing something here ? Is it a problem with the Metrowerks compiler ?

 

I am using PowerPC EABI Linker. Version: Code Warrior PowerPC ISA, Release 8.5 Build 50425.

Thanks !!

Labels (1)
0 Kudos
3 Replies

298 Views
Lundin
Senior Contributor IV

I haven't used C++ in Codewarrior but a qualified guess is the classic problem with linking of template functions:

http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

 

Whether Codewarrior supports export keyword or not, I have no idea.

0 Kudos

298 Views
CompilerGuru
NXP Employee
NXP Employee

as the error is a compilation failure and not a link time failure, I doubt it is that issue.

 

I would recommend to show a complete example and not just snippets, there is just too much undefined otherwise.

The text "void register_callback ( (void (*)())(&call_stub<T>) )" is not legal in C++ code as 

it is neither a declaration nor a statemen, seems to be some psedocode.

 

Either way only a concrete instance of the call_stub template function has an address (call_stub<int>), the address of call_stub<T> only makes sense if used inside of another template.

 

Daniel

0 Kudos

298 Views
cw_Potz
Contributor I

Actually the project on which I am working is quite a big one. So I just wrote the minimum stuff. Please check the code below, maybe better than previous time.

 

Thanks !!

 

 

class MyThread
{
    template <typename T>
    static void
    call_stub (void *argument)
    {
    }

    static void
    call_stub_ (void *argument)
    {
    }

public:
    template <typename T>
    MyThread (T &function, bool joinable = false)
    {
        int result = register_callback ((void (*)())(&call_stub<T>), joinable, (void*)&function);
       
        int result = register_callback ((void (*)())(&call_stub_), joinable, (void*)&function);

    }
};

int
register_callback(

                void (*entryAddr)(void),

                bool joinable,

                void *arg

)

{
    // creates a thread and register the callback function.
}

0 Kudos