-pedantic warning and pthread_create

2019-08-02 01:15发布

I'm newbie in the ansi and iso world, i compiled my program with :

-asni -pedantic -std=c++11 -std=c++98 

Now, i get the following warning:

 warning: converting from 'void (NetworkSocket::*)()' to 'void* (*)(void*)' [-pedantic]

for the following line:

if (pthread_create(this->threadArray, NULL, (void*(*)(void*)) &NetworkSocket::threadProcedure  , (void *)this) != 0)
        { /* error */      }

How can i pass pedantic warning?

1条回答
干净又极端
2楼-- · 2019-08-02 02:11

pthread_create is a C function expecting a C function taking a void pointer, and returning a void pointer. So you can use such a C function to dispatch the call to you member function, if you use the this pointer as thread argument:

extern "C" void* startThread( void* p )
{
    static_cast< NetworkSocket* >( p )->threadProcedure();

    return 0;
} 

if ( pthread_create( this->threadArray, 0, startThread, this ) )
   ...
查看更多
登录 后发表回答