参照元†
- 関数や変数に対して出る警告 'defined but not used'
(定義されているが使用されていない)を抑制するための属性の宣言
include/linux/compiler.h†
/*
* Allow us to avoid 'defined but not used' warnings on functions and data,
* as well as force them to be emitted to the assembly file.
*
* As of gcc 3.4, static functions that are not marked with attribute((used))
* may be elided from the assembly file. As of gcc 3.4, static data not so
* marked will not be elided, but this may change in a future gcc version.
*
* NOTE: Because distributions shipped with a backported unit-at-a-time
* compiler in gcc 3.3, we must define __used to be __attribute__((used))
* for gcc >=3.3 instead of 3.4.
*
* In prior versions of gcc, such functions and data would be emitted, but
* would be warned about except with attribute((unused)).
*
* Mark functions that are referenced only in inline assembly as __used so
* the code is emitted even though it appears to be unreferenced.
*/
#ifndef __used
- gcc 以外のコンパイラで、__used に特別な意味を定めて居ない場合
# define __used /* unimplemented */
#endif
include/linux/compiler-gcc3.h†
#if __GNUC_MINOR__ >= 3
# define __used __attribute__((__used__))
- 変数に対して、__attribute__( (used) ) を宣言できる。
#else
# define __used __attribute__((__unused__))
- unused でも used でも効力は同じらしい。
変数に対して、__attribute__( (used) ) を宣言できないため、
unused を使うらしい。
- この辺りの理屈はよくわかりません。正直どうでもいい…。
#endif
include/linux/compiler-gcc4.h†
#define __used __attribute__((__used__))
コメント†