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;
}
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).
__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.
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.
You can cast the parameter to void
like this:
void *timer1_function(void * parameter1) {
(void) parameter1; // Suppress the warning.
// <statement>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With