The unused function attribute prevents the compiler from generating warnings if the function is not referenced. This does not change the behavior of the unused function removal process.
Note:
By default, the compiler does not warn about unused functions. Use -Wunused-function to enable this warning specifically, or use
an encompassing -W value such as -Wall.
The __attribute__((unused)) attribute
can be useful if you usually want to warn about unused functions, but want to suppress
warnings for a specific set of functions.
Example
static int unused_no_warning(int b) __attribute__((unused));
static int unused_no_warning(int b)
{
return b++;
}
static int unused_with_warning(int b);
static int unused_with_warning(int b)
{
return b++;
}
Compiling this example with -Wall results in the following warning:
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.