The compiler can warn if a variable is declared but is never referenced. The __attribute__((unused)) attribute informs the compiler to expect an unused variable, and tells it not to issue a warning.
Note:
By default, the compiler does not warn about unused variables. Use -Wunused-variable to enable this warning specifically, or use an
encompassing -W value such as -Weverything.
The __attribute__((unused)) attribute
can be used to warn about most unused variables, but suppress warnings for a specific set
of variables.
Example
void foo()
{
static int aStatic =0;
int aUnused __attribute__((unused));
int bUnused;
aStatic++;
}
When compiled with a suitable -W setting, the compiler warns that bUnused is declared but never
referenced, but does not warn about aUnused:
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.