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 (Embedded Coder).
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 (Embedded Coder), and Create Storage Classes by Using the Custom Storage Class Designer (Embedded Coder).
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 (Embedded Coder) 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 (Embedded Coder) 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 (Embedded Coder) for more details.If the storage class has an imported
DataScope
setting, see Imported Scope Data Declaration File Packaging (Embedded Coder) for more details.
For storage classes with a customizable DefinitionFile
property, see
Data Definition File Packaging (Embedded Coder) for more details.
Storage Class | Storage Type (Embedded Coder) | Data Scope (Embedded Coder) | Data Initialization (Embedded Coder) | Header File (Embedded Coder) | Definition File (Embedded Coder) | Owner | Preserve array dimensions (Embedded Coder) |
---|---|---|---|---|---|---|---|
ExportedGlobal (Embedded Coder) | Unstructured | Exported | Auto |
|
|
| off |
ImportedExtern, ImportedExternPointer (Embedded Coder) | Unstructured | Imported | Some signals and states:
Other data: In external code | Customizable | In external code |
| off |
Const, Volatile, and ConstVolatile (Embedded Coder) | Unstructured | Exported | Auto | Customizable | Customizable | Customizable | Customizable |
Define, ImportedDefine (Embedded Coder) | Unstructured | Exported | Macro | Customizable | None |
| off |
ExportToFile (Embedded Coder) | Unstructured | Exported | Auto | Customizable | Customizable | Customizable | Customizable |
ImportFromFile (Embedded Coder) | Unstructured | Imported | In external code | Customizable | In external code |
| Customizable |
FileScope (Embedded Coder) | Unstructured | File | Auto | None |
|
| Customizable |
Localizable (Embedded Coder) | 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 (Embedded Coder) | Structured | Exported | Auto |
|
|
| off |
Bitfield (Embedded Coder) | Structured | Exported | Auto |
|
|
| off |
GetSet (Embedded Coder) | Unstructured | Imported | In external code | In external code | In external code |
| Customizable |
CompilerFlag (Embedded Coder) | Unstructured | Imported | Macro | None | None |
| off |
Reusable (Embedded Coder) | Unstructured | Customizable | Dynamic | File scope: None Exported or Imported scope: Customizable | File scope:
Exported or Imported scope: Customizable | Customizable | off |
MultiInstance (Embedded Coder) | 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 (Embedded Coder) 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 (Embedded Coder).
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 (Embedded Coder) 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 (Embedded Coder),
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 (Embedded Coder) 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 (Embedded Coder) 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 (Embedded Coder), 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 (Embedded Coder)
- C Data Code Interface Configuration for Model Interface Elements (Embedded Coder)
- Control Placement of Global Data Definitions and Declarations in Generated Files (Embedded Coder)
- Organize Parameter Data into a Structure by Using Struct Storage Class (Embedded Coder)
- Control Ownership of Data (Embedded Coder)