头文件编译时错误求助:sigset_t类型不兼容参数传递问题
Fixing the "Incompatible Type" Compile Error in
pthread_setcancelstate The error you're hitting stems from a small but critical mistake in how you're using the sigismember() function. Let's break this down clearly:
The Root Cause
The sigismember() function requires its first argument to be a pointer to a sigset_t (const sigset_t *), but in your code, you're passing the sigset_t variable old directly (by value) instead of its memory address. This mismatch is why the compiler complains about passing a sigset_t to a parameter expecting const sigset_t *.
Corrected Code
Here's the fixed version of your function, with the problematic line adjusted:
static int pthread_setcancelstate(int state, int *oldstate) { sigset_t new, old; int ret; sigemptyset(&new); sigaddset(&new, SIG_CANCEL_SIGNAL); ret = pthread_sigmask( state == PTHREAD_CANCEL_ENABLE ? SIG_BLOCK : SIG_UNBLOCK, &new, &old ); if(oldstate != NULL) { // Fixed: pass &old instead of old to sigismember() *oldstate = sigismember(&old, SIG_CANCEL_SIGNAL) == 0 ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE; } return ret; }
Why This Works
sigismember(const sigset_t *set, int signo)checks if a signal exists in the set pointed to byset. By passing&old, you're providing the pointer it needs to access thesigset_tvariable you populated withpthread_sigmask().- The rest of your code was already correct: you’re using
&newand&oldwithpthread_sigmask()(which also expects pointers tosigset_t), so that part never caused the error.
内容的提问来源于stack exchange,提问作者Golu
相关产品推荐
相关产品推荐

