Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

defining unused parameters in C

I need to use pthreat but I dont need to pass any argument to the function. Therefore, I pass NULL to the function on pthread_create. I have 7 pthreads, so gcc compiler warns me that I have 7 unsued parameters. How can I define these 7 parameters as unused in C programming? If I do not define these parameters as unused, would it cause any problem? Thank you in advance for the responses.

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;
}
like image 723
johan Avatar asked Apr 30 '12 21:04

johan


People also ask

What is unused parameter in C?

Unused parameters : __attribute__((unused))It is not (yet) part of the C standard, but is supported by the GNU gcc compiler as an extension (ie. works with gcc, but maybe not with other compilers).

What is __ Attribute__ unused ))?

__attribute__((unused)) variable attribute Normally, the compiler warns if a variable is declared but is never referenced. This attribute informs the compiler that you expect a variable to be unused and tells it not to issue a warning if it is not used.

What are unused variables?

An unused variable refers to a variable of which the data element structure is unreferenced in the main program, including the parent and the subordinate items. An unused copybook refers to a copybook with the aforementioned copybook of an unused variable.


1 Answers

You can cast the parameter to void like this:

void *timer1_function(void * parameter1) {
  (void) parameter1; // Suppress the warning.
  // <statement>
}
like image 118
Adam Liss Avatar answered Sep 21 '22 15:09

Adam Liss