このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
coder.storageClass
グローバル変数にストレージ クラスを代入
説明
coder.storageClass( は、グローバル変数 global_name, storage_class)global_name にストレージ クラス storage_class を代入します。
グローバル変数へのストレージ クラスの代入は、グローバル変数を宣言する関数で行います。ストレージ クラスを複数の関数で代入する必要はありません。
coder.storageClass を使用するには Embedded Coder® ライセンスが必要です。C/C++ ライブラリまたは実行可能ファイルの生成に Embedded Coder プロジェクトまたは構成オブジェクトを使用する場合のみ、コード生成ソフトウェアで coder.storageClass の呼び出しが認識されます。
例
関数 addglobals_ex で、グローバル変数 myglobalone に 'ExportedGlobal' ストレージ クラスを代入し、グローバル変数 myglobaltwo に 'ExportedDefine' ストレージ クラスを代入します。
function y = addglobals_ex(x) %#codegen % Define the global variables. global myglobalone; global myglobaltwo; % Assign the storage classes. coder.storageClass('myglobalone','ExportedGlobal'); coder.storageClass('myglobaltwo','ExportedDefine'); y = myglobalone + myglobaltwo + x; end
ライブラリまたは実行可能ファイル用のコード構成オブジェクトを作成します。
cfg = coder.config('dll','ecoder', true);
コードを生成します。この例では、myglobalone および myglobaltwo の型と初期値を -globals 引数を使用して指定します。代わりに、MATLAB® グローバル ワークスペースでグローバル変数を定義することもできます。入力引数 x の型を指定するには、-args オプションを使用します。
codegen -config cfg -globals {'myglobalone', 1, 'myglobaltwo', 2} -args {1} addglobals_ex -report
初期値の 1 と 2 から、myglobalone と myglobaltwo の型は double であると codegen で特定されます。codegen により、エクスポートされる変数 myglobalone と myglobaltwo が定義および宣言されます。myglobalone を 1.0、myglobaltwo を 2.0 に初期化するコードが生成されます。
myglobaltwo と myglobalone の生成コードを表示するには、View report リンクをクリックします。
myglobaltwoはaddglobals_ex.hのExported data defineセクションで定義されています。/* Exported data define */ /* Definition for custom storage class: ExportedDefine */ #define myglobaltwo 2.0
myglobaloneはaddglobals_ex.cのVariable Definitionsセクションで定義されています。/* Variable Definitions */ /* Definition for custom storage class: ExportedGlobal */ double myglobalone;
myglobaloneはaddglobals_ex.hのVariable Declarationsセクションでexternとして宣言されています。/* Variable Declarations */ /* Declaration for custom storage class: ExportedGlobal */ extern double myglobalone;
myglobaloneはaddglobals_ex_initialize.cで初期化されています。/* Include Files */ #include "addglobals_ex_initialize.h" #include "addglobals_ex.h" #include "addglobals_ex_data.h" /* Function Definitions */ /* * Arguments : void * Return Type : void */ void addglobals_ex_initialize(void) { myglobalone = 1.0; isInitialized_addglobals_ex = true; }
関数 addglobal_im で、グローバル変数 myglobal に 'ImportedExtern' ストレージ クラスを代入します。
function y = addglobal_im(x) % Define the global variable. global myglobal; % Assign the storage classes. coder.storageClass('myglobal','ImportedExtern'); y = myglobal + x; end
インポートされる変数 myglobal を定義および初期化するファイル c:\myfiles\myfile.c を作成します。
#include <stdio.h> /* Variable definitions for imported variables */ double myglobal = 1.0;
コード構成オブジェクトを作成します。myfile.c を含めるようにコード生成パラメーターを構成します。出力タイプが 'lib' の場合やソース コードのみを生成する場合は、このファイルを提供せずにコードを生成できます。それ以外の場合は、このファイルを提供する必要があります。
cfg = coder.config('dll','ecoder', true); cfg.CustomSource = 'myfile.c'; cfg.CustomInclude = 'c:\myfiles';
コードを生成します。この例では、myglobal の型と初期値を -globals 引数を使用して指定します。代わりに、MATLAB グローバル ワークスペースでグローバル変数を定義することもできます。インポートされるグローバル変数については、コード生成ソフトウェアで初期値を使用して型のみを特定します。
codegen -config cfg -globals {'myglobal', 1} -args {1} addglobal_im -report
初期値 1 から、myglobal の型は double であると codegen で特定されます。codegen により、インポートされるグローバル変数 myglobal が宣言されます。myglobal の定義や myglobal を初期化するコードの生成は行われません。myglobal を定義および初期化するコードは myfile.c から提供されます。
myglobal の生成コードを表示するには、View report リンクをクリックします。
myglobal は addglobal_im_data.h の Variable Declarations セクションで extern として宣言されています。
/* Variable Declarations */ /* Declaration for custom storage class: ImportedExtern */ extern double myglobal;
関数 addglobal_imptr で、グローバル変数 myglobal に 'ImportedExternPointer' ストレージ クラスを代入します。
function y = addglobal_imptr(x) % Define the global variable. global myglobal; % Assign the storage classes. coder.storageClass('myglobal', 'ImportedExternPointer'); y = myglobal + x; end
インポートされるグローバル変数 myglobal を定義および初期化するファイル c:\myfiles\myfile.c を作成します。
#include <stdio.h> /* Variable definitions for imported variables */ double v = 1.0; double *myglobal = &v;
コード構成オブジェクトを作成します。myfile.c を含めるようにコード生成パラメーターを構成します。出力タイプが 'lib' の場合やソース コードのみを生成する場合は、このファイルを提供せずにコードを生成できます。それ以外の場合は、このファイルを提供する必要があります。
cfg = coder.config('dll','ecoder', true); cfg.CustomSource = 'myfile.c'; cfg.CustomInclude = 'c:\myfiles';
コードを生成します。この例では、グローバル変数 myglobal の型と初期値を -globals 引数を使用して指定します。代わりに、MATLAB グローバル ワークスペースでグローバル変数を定義することもできます。インポートされるグローバル変数については、コード生成ソフトウェアで初期値を使用して型のみを特定します。
codegen -config cfg -globals {'myglobal', 1} -args {1} addglobal_imptr -report
初期値 1 から、myglobal の型は double であると codegen で特定されます。codegen により、インポートされるグローバル変数 myglobal が宣言されます。myglobal の定義や myglobal を初期化するコードの生成は行われません。myglobal を定義および初期化するコードは myfile.c から提供されます。
myglobal の生成コードを表示するには、View report リンクをクリックします。
myglobal は addglobal_imptr_data.h の Variable Declarations セクションで extern として宣言されています。
/* Variable Declarations */ /* Declaration for custom storage class: ImportedExternPointer */ extern double *myglobal;
入力引数
global_name はグローバル変数の名前です。文字ベクトルとして指定します。global_name はコンパイル時の定数でなければなりません。
例: 'myglobal'
データ型: char
global_var に代入するストレージ クラス。storage_class は次の値のいずれかになります。
| ストレージ クラス | 説明 |
|---|---|
'ExportedGlobal' |
|
'ExportedDefine' | ヘッダー ファイル |
'ImportedExtern' | ヘッダー ファイル |
'ImportedExternPointer' | ヘッダー ファイル |
グローバル変数にストレージ クラスを代入しない場合、宣言の場所を除き、変数は
'ExportedGlobal'ストレージ クラスの場合と同じように動作します。ストレージ クラスが'ExportedGlobal'の場合、ファイルでグローバル変数が宣言されます。グローバル変数にストレージ クラスがない場合は、ファイルentry_point_name.hで変数が宣言されます。entry_point_name_data.h
データ型: char
制限
グローバル変数にストレージ クラスを代入した後に、そのグローバル変数に別のストレージ クラスを代入することはできません。
定数のグローバル変数にストレージ クラスを代入することはできません。
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
バージョン履歴
R2015b で導入
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)