You copied the Doc URL to your clipboard.

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 that you expect a variable to be unused 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 useful if you usually want to warn about unused variables, but want to 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.