3.32 __attribute__((unused)) variable attribute

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:
armclang --target=aarch64-arm-none-eabi -c test_unused.c -Wall            
test_unused.c:5:7: warning: unused variable 'bUnused' [-Wunused-variable]
  int bUnused;
      ^
1 warning generated.
Related reference
3.17 __attribute__((unused)) function attribute
Non-ConfidentialPDF file icon PDF versionARM DUI0774E
Copyright © 2014-2016 ARM. All rights reserved.