0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GCC __attribute__((パラメータ))とはなにか

Posted at

__attribute__((パラメータ))とはなにか?

ソースコードリーディングをしていると、__attribute__((◯◯))によく出くわします。気になったので調べてみました。

機能

GNU CおよびC++では、関数属性を使用して、コンパイラが呼び出しを最適化したり、コードが正しいかどうかをより注意深くチェックしたりするのに役立つ特定の関数プロパティを指定できます。
たとえば、属性を使用して、関数が決して返さないnoreturn、引数の値のみに依存する値を返すconst、またはprintfスタイルの引数を持つformat等を指定できます。

属性を使用して、注釈が付けられている関数内のメモリ配置、コード生成オプション、または呼び出し/戻り規則を制御することもできます。

GCCは、変数宣言、ラベル、列挙子、ステートメント、および型の属性もサポートします。

Syntax

関数属性は、関数の宣言で__attribute__キーワードによって導入され、その後に二重括弧で囲まれた属性指定が続きます。
宣言で複数の属性を指定するには、二重括弧内でコンマで区切るか、1つの属性指定の直後に別の属性を指定します。

__attribute__ ((パラメータ))

具体例

__attribute__((destructor))で関数にdestructor属性を付与することができます。

C言語 __attribute__((destructor))を使用したメモリリークチェック - Qiita

参考

attribute ‐ 通信用語の基礎知識
Function Attributes (Using the GNU Compiler Collection (GCC))

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?