You copied the Doc URL to your clipboard.

__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.


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.


void foo()
    static int aStatic =0;
    int aUnused __attribute__((unused));
    int bUnused;

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.