表示: Delphi C++
表示設定

__declspec(selectany)

提供:RAD Studio
移動: 案内, 検索

キーワード(アルファベット順):インデックス への移動


カテゴリ

修飾子拡張キーワード記憶クラス指定子

構文

__declspec( selectany ) declarator

通常、グローバル データ項目はアプリケーションまたはライブラリで 1 度だけ初期化できます。この属性は、同じヘッダーが複数のソース ファイルで使われる場合に、ヘッダーによって定義されたグローバル データを初期化するために使用できます。

メモ: この属性は、外部から参照可能なグローバル データ項目を実際に初期化するときだけに利用できます。

次のコードは、selectany 属性の使い方を示しています。

 //Correct - x1 is initialized and externally visible
 __declspec(selectany) int x1=1;
 
 //Incorrect - const is by default static in C++, so
 //x2 is not visible externally (This is OK in C, since
 //const is not by default static in C)
 const __declspec(selectany) int x2=2;
 
 //Correct - x3 is extern const, so externally visible
 extern const __declspec(selectany) int x3=3;
 
 //Correct - x4 is extern const, so it is externally visible
 extern const int x4;
 const __declspecselectany) int x4=4;
 
 //Incorrect - __declspec(selectany) is applied to the uninitialized declaration of x5 
 extern __declspec(selectany) int x5;

関連項目

他言語版