You copied the Doc URL to your clipboard.

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

Note

This variable attribute is a GNU compiler extension that the ARM compiler supports.

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

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.

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 -c test_unused.c -Wall            
test_unused.c:5:7: warning: unused variable 'bUnused' [-Wunused-variable]
  int bUnused;
      ^
1 warning generated.
Was this page helpful? Yes No