Annotate C with GCC Function Attributes

A nice feature of GCC – which is not standard – is support for annotate C code and selectively avoid or raise warnings.

Example 1. A function which has a willingly unused variable can avoid a warning at compile time

int my_function(int a, int b, __attribute__((unused)) int c_only_for_debug) {

printf(“print %d\n”, a+b);

#ifdef DEBUG

printf(“on debug print %d too\n”, c_only_for_debug);

#endif

}

More examples soon ;)