Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inhibit error messages for unused static functions?

Tags:

c

gcc

In C code, if a function is used exclusively within a file, it's good practice to declare it to be static.

But sometimes I define a function to be static but don't actually use it (yet), in which case the compiler complains at me:

../src/app.c:79:12: error: 'foo' defined but not used [-Werror=unused-function]

What's the right way to tell the compiler (gcc in this case) that unused static functions are okay?

like image 279
fearless_fool Avatar asked Sep 11 '25 07:09

fearless_fool


2 Answers

You can add the unused attribute to the function:

__attribute__((unused))
static void foo(void)
{
}
like image 173
dbush Avatar answered Sep 13 '25 21:09

dbush


You can disable that specific error by providing this argument to GCC:

-Wno-unused-function

The error itself contained a hint that you could do this.

like image 22
David Grayson Avatar answered Sep 13 '25 19:09

David Grayson