【发布时间】:2012-04-30 21:47:02
【问题描述】:
我需要使用 pthreat 但我不需要将任何参数传递给函数。因此,我将 NULL 传递给 pthread_create 上的函数。我有 7 个 pthread,所以 gcc 编译器警告我有 7 个未使用的参数。如何将这 7 个参数定义为 C 编程中未使用的参数?如果我不将这些参数定义为未使用,会导致任何问题吗?提前感谢您的回复。
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;
}
【问题讨论】:
-
如果它们未被使用,则意味着没有对这些变量进行任何有意义的操作,并且(在大多数情况下)它们可以安全地删除。这是一个警告,而不是错误,所以它可以被忽略。 忽略它通常不是一个好主意,但你可以。
-
@hmjd - C++ 允许,而不是 C。