-pedantic warning and pthread_create

谁说胖子不能爱 提交于 2019-12-13 02:34:39

问题


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:


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 ) )
   ...


来源:https://stackoverflow.com/questions/11701766/pedantic-warning-and-pthread-create

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!