joh*_*han 8 c gcc posix pthreads
我需要使用pthreat但我不需要将任何参数传递给函数.因此,我将NULL传递给pthread_create上的函数.我有7个pthreads,所以gcc编译器警告我有7个未完成的参数.如何在C编程中将这7个参数定义为未使用?如果我没有将这些参数定义为未使用,是否会导致任何问题?提前感谢您的回复.
void *timer1_function(void * parameter1){
//<statement>
}
int main(int argc,char *argv[]){
int thread_check1;
pthread_t timer1;
thread_check1 = pthread_create( &timer1, NULL, timer1_function, NULL);
if(thread_check1 !=0){
perror("thread creation failed");
exit(EXIT_FAILURE);
}
while(1){}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Ada*_*iss 18
您可以将参数强制转换为void:
void *timer1_function(void * parameter1) {
(void) parameter1; // Suppress the warning.
// <statement>
}
Run Code Online (Sandbox Code Playgroud)
Kyl*_*nes 17
GCC具有"属性"功能,可用于标记未使用的参数.使用
void *timer1_function(__attribute__((unused))void *parameter1)
Run Code Online (Sandbox Code Playgroud)