Use Built-In and Predefined Storage Classes to Represent Data in Generated Code
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,
refers to the current model
containing the data element that the storage class is applied to.model
For information about each storage class and its configurable properties (including
Owner
), 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:
If the storage class has an exported
DataScope
setting, see Exported Scope Data Declaration File Packaging for more details.If the storage class has an imported
DataScope
setting, see Imported Scope Data Declaration File Packaging for more details.
For storage classes with a customizable DefinitionFile
property, see
Data 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 |
|
|
| off |
ImportedExtern, ImportedExternPointer | Unstructured | Imported | Some signals and states:
Other data: In external code | Customizable | In external code |
| off |
Const, Volatile, and ConstVolatile | Unstructured | Exported | Auto | Customizable | Customizable | Customizable | Customizable |
Define, ImportedDefine | Unstructured | Exported | Macro | Customizable | None |
| off |
ExportToFile | Unstructured | Exported | Auto | Customizable | Customizable | Customizable | Customizable |
ImportFromFile | Unstructured | Imported | In external code | Customizable | In external code |
| Customizable |
FileScope | Unstructured | File | Auto | None |
|
| Customizable |
Localizable | Unstructured | Function or File scope: Global scope:
| Function scope: File or global scope: | Function or File scope: None Global scope: Customizable | Function scope: Function source file File scope:
Global scope: Customizable |
| Customizable |
Struct | Structured | Exported | Auto |
|
|
| off |
Bitfield | Structured | Exported | Auto |
|
|
| off |
GetSet | Unstructured | Imported | In external code | In external code | In external code |
| Customizable |
CompilerFlag | Unstructured | Imported | Macro | None | None |
| off |
Reusable | Unstructured | Customizable | Dynamic | File scope: None Exported or Imported scope: Customizable | File scope:
Exported or Imported scope: Customizable | Customizable | off |
MultiInstance | Single-instance:
Multi-instance:
| Exported | Single-instance: Multi-instance: None |
| Single-instance:
Multi-instance: None |
| off |
Note
The code generator does not initialize data mapped to the
Localizable
storage class if both of the following are true:
The data is represented by a variable of function scope with zero initial value.
The model configuration parameter Remove local variable initialization to zero value is enabled.
The code generator does not define or initialize data mapped to a storage class whose
Owner
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 |
|
ImportedExtern | extern | External code |
ImportedExternPointer | extern | External code |
Const | extern const | const
|
Volatile | extern volatile | volatile |
ConstVolatile
| extern const volatile | const volatile |
Define | #define | None |
ImportedDefine | #define | None |
ExportToFile | extern |
|
ImportFromFile | extern | External code |
FileScope | static | static
|
Struct | Type definition: typedef struct struct_name_tag { datatype identifier; } struct_name_type; Declaration: extern 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; |
|
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 |
|
ImportedExtern | extern | External code |
ImportedExternPointer | extern | External code |
Volatile | extern volatile | volatile |
ExportToFile | extern |
|
ImportFromFile | extern | External code |
FileScope | static | static
|
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; |
|
Bitfield | Type definition: typedef struct struct_name_tag { datatype identifier : nbits; } struct_name_type; Declaration: extern struct_name_type struct_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:
ExportToFile
Const
Volatile
ConstVolatile
Define
Localizable
(global scope)Reusable
(exported scope)
Data declaration | HeaderFile | Location |
---|---|---|
Auto | None |
|
InSourceFile | None |
Other storage class: No declaration generated |
InSeparateHeaderFile | None | Header file specified by Data declaration filename,
such as |
Any setting |
|
|
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:
ImportedExtern
ImportedExternPointer
ImportedFromFile
Reusable
(imported scope)
File packaging format | HeaderFile | Location |
---|---|---|
Modular | None |
|
Compact | None |
|
CompactWithDataFile | None |
|
Any setting |
|
|
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:
ExportToFile
Const
Volatile
ConstVolatile
Localizable
(global scope)Reusable
(exported scope)
Data definition | DefinitionFile | Owner | Location |
---|---|---|---|
Auto | None | None or current model name |
|
InSourceFile | None | None or current model name |
|
InSeparateSourceFile | None | None or current model name | Header file specified by Data definition filename, such
as |
Any setting |
| None or current model name |
|
Any setting | Other model name | No definition generated when Use owner from data object for data definition placement is enabled |
See Also
Topics
- Choose Storage Class for Controlling Data Representation in Generated Code
- C Data Code Interface Configuration for Model Interface Elements
- Control Placement of Global Data Definitions and Declarations in Generated Files
- Organize Parameter Data into a Structure by Using Struct Storage Class
- Control Ownership of Data