Use Built-In and Predefined Storage Classes to Represent Data in Generated Code - MATLAB & Simulink (original) (raw)

Use built-in storage classes or predefined storage classes in the Embedded CoderĀ® Dictionary to control the appearance and placement of data elements in your generated code. When choosing a storage class to meet your requirements, consider both the predefined and customizable properties of that storage class. For an overview of each built-in or predefined storage class and its properties, see Choose Storage Class for Controlling Data Representation in Generated Code.

If you have special requirements not met by the listed storage classes and you are generating code for an ERT-based target, you can define and use a new storage class. See Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture, and Create Storage Classes by Using the Custom Storage Class Designer.

Choose Built-In or Predefined Storage Class Based on Properties

The following table lists key properties to consider when you choose a built-in or predefined storage class to represent your data. While some properties of a particular storage class are customizable, others are predefined and shown explicitly in the table. Here, _`model`_ refers to the current model containing the data element that the storage class is applied to.

For information about each storage class and its configurable properties (includingOwner), see Choose Storage Class for Controlling Data Representation in Generated Code or click the name of the storage class in the table. For information about all storage class properties (except Owner) and their configuration settings, see Embedded Coder Dictionary or click the name of the property in the table.

For storage classes with a customizable HeaderFile property:

For storage classes with a customizable DefinitionFile property, seeData Definition File Packaging for more details.

Storage Class Storage Type Data Scope Data Initialization Header File Definition File Owner Preserve array dimensions
ExportedGlobal Unstructured Exported Auto model.h model.c model off
ImportedExtern, ImportedExternPointer Unstructured Imported Some signals and states:DynamicOther data: In external code Customizable In external code model off
Const, Volatile, and ConstVolatile Unstructured Exported Auto Customizable Customizable Customizable Customizable
Define, ImportedDefine Unstructured Exported Macro Customizable None model off
ExportToFile Unstructured Exported Auto Customizable Customizable Customizable Customizable
ImportFromFile Unstructured Imported In external code Customizable In external code model Customizable
FileScope Unstructured File Auto None model.c model Customizable
Localizable Unstructured Function or File scope: FileGlobal scope:Exported Function scope: Static inside functionFile or global scope: Static outside function Function or File scope: NoneGlobal scope: Customizable Function scope: Function source fileFile scope:model.cGlobal scope: Customizable model Customizable
Struct Structured Exported Auto model.h model.c model off
Bitfield Structured Exported Auto model.h model.c model off
GetSet Unstructured Imported In external code In external code In external code model Customizable
CompilerFlag Unstructured Imported Macro None None model off
Reusable Unstructured Customizable Dynamic File scope: NoneExported or Imported scope: Customizable File scope:model.cExported or Imported scope: Customizable Customizable off
MultiInstance Single-instance:UnstructuredMulti-instance:Structured Exported Single-instance: AutoMulti-instance: None model.h Single-instance:model.cMulti-instance: None model off

Note

The code generator does not initialize data mapped to theLocalizable storage class if both of the following are true:

The code generator does not define or initialize data mapped to a storage class whoseOwner property is set to a different model name than that of the current model. See Data Definition File Packaging.

Storage Classes and Data Declarations and Definitions

Declarations and definitions of data elements in the generated code depend on properties of the storage class assigned to that data element. The following tables summarize how built-in or predefined storage classes control declaration and definition statements in the code.

Data Declarations and Definitions for Parameters

Storage Class Declaration Definition
ExportedGlobal extern datatype identifier; datatype identifier =value;
ImportedExtern extern datatype identifier; External code
ImportedExternPointer extern datatype *identifier; External code
Const extern const datatype identifier; const datatype identifier =value;
Volatile extern volatile datatype identifier; volatile datatype identifier =value;
ConstVolatile extern const volatile datatype identifier; const volatile datatype identifier =value;
Define #define identifier value None
ImportedDefine #define identifier value None
ExportToFile extern datatype identifier; datatype identifier =value;
ImportFromFile extern datatype identifier; External code
FileScope static datatype identifier =value; static datatype identifier =value;
Struct Type definition:typedef struct struct_name_tag { datatype identifier; } struct_name_type;Declaration:extern struct_name_type struct_name; struct_name_type_struct_name_ = {value;}
Bitfield Type definition:typedef struct struct_name_tag { datatype identifier : nbits; } struct_name_type;Declaration:extern struct_name_type struct_name; struct_name_type_struct_name_ = {value;}
GetSet External code External code
CompilerFlag None None
MultiInstance Single-instance:extern datatype identifier;Multi-instance:typedef struct {datatype identifier;} model_T; Single-instance:datatype identifier = value;Multi-instance: None

Data Declarations and Definitions for Root-Level I/O Data, Signals, States, and Datastores

Storage Class Declaration Definition
ExportedGlobal extern datatype identifier; datatype identifier;
ImportedExtern extern datatype identifier; External code
ImportedExternPointer extern datatype *identifier; External code
Volatile extern volatile datatype identifier; volatile datatype identifier;
ExportToFile extern datatype identifier; datatype identifier;
ImportFromFile extern datatype identifier; External code
FileScope static datatype identifier; static datatype identifier;
Localizable Function scope:datatype identifier;File scope:static datatype identifier;Global scope:datatype identifier; Function scope:datatype identifier;File scope:static datatype identifier;Global scope:datatype identifier;
Struct Type definition:typedef struct struct_name_tag { datatype identifier; } struct_name_type;Declaration:extern struct_name_type struct_name; struct_name_type_struct_name_;
Bitfield Type definition:typedef struct struct_name_tag { datatype identifier : nbits; } struct_name_type;Declaration:extern struct_name_type struct_name; bitfield_name_type_bitfield_name_;
GetSet External code External code
Reusable File scope:static datatype identifier;Exported or Imported scope:extern datatype identifier; File scope:static datatype identifier;Exported scope:datatype identifier;Imported scope: External code
MultiInstance Single-instance:extern datatype identifier;Multi-instance:typedef struct {datatype identifier;} model_T; Single-instance:datatype identifier;Multi-instance: None

Storage Classes and Data Declaration and Definition File Packaging

Exported Scope Data Declaration File Packaging

The following table summarizes how file placement of data declarations depends on the**Data declaration** model configuration parameter and the HeaderFile property, if available, for the following storage classes:

Data declaration HeaderFile Location
Auto None model.h
InSourceFile None Define:model.h Other storage class: No declaration generated
InSeparateHeaderFile None Header file specified by Data declaration filename, such as global.h
Any setting my_header.h my_header.h

Imported Scope Data Declaration File Packaging

The following table summarizes how placement of data declarations depends on the**File packaging format** model configuration parameter and the HeaderFile property, if available, for the following storage classes:

File packaging format HeaderFile Location
Modular None model_private.h
Compact None model.h
CompactWithDataFile None model.h
Any setting my_header.h my_header.h

Data Definition File Packaging

The following table summarizes how file placement of data definitions depends on the**Data definition** model configuration parameter, and the DefinitionFile and Owner properties, if available, for the following storage classes:

Data definition DefinitionFile Owner Location
Auto None None or current model name model.c
InSourceFile None None or current model name model.c
InSeparateSourceFile None None or current model name Header file specified by Data definition filename, such as global.c
Any setting my_source.c None or current model name my_source.c
Any setting Other model name No definition generated when Use owner from data object for data definition placement is enabled

See Also

Topics