Main Content

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, 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 (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:

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

Storage ClassStorage TypeData ScopeData InitializationHeader FileDefinition FileOwnerPreserve array dimensions
ExportedGlobalUnstructuredExportedAutomodel.hmodel.cmodeloff
ImportedExtern, ImportedExternPointerUnstructuredImported

Some signals and states: Dynamic

Other data: In external code

Customizable In external codemodeloff
Const, Volatile, and ConstVolatileUnstructuredExportedAutoCustomizableCustomizableCustomizableCustomizable
Define, ImportedDefineUnstructuredExportedMacroCustomizableNonemodeloff
ExportToFileUnstructuredExportedAutoCustomizableCustomizableCustomizableCustomizable
ImportFromFileUnstructuredImportedIn external codeCustomizableIn external codemodelCustomizable
FileScopeUnstructuredFileAutoNonemodel.cmodelCustomizable
LocalizableUnstructured

Function or File scope: File

Global scope: Exported

Function scope: Static inside function

File or global scope: Static outside function

Function or File scope: None

Global scope: Customizable

Function scope: Function source file

File scope: model.c

Global scope: Customizable

modelCustomizable
StructStructuredExportedAutomodel.hmodel.cmodeloff
BitfieldStructuredExportedAutomodel.hmodel.cmodeloff
GetSetUnstructuredImportedIn external codeIn external codeIn external codemodelCustomizable
CompilerFlagUnstructuredImportedMacroNoneNonemodeloff
ReusableUnstructuredCustomizableDynamic

File scope: None

Exported or Imported scope: Customizable

File scope: model.c

Exported or Imported scope: Customizable

Customizableoff
MultiInstance

Single-instance: Unstructured

Multi-instance: Structured

Exported

Single-instance: Auto

Multi-instance: None

model.h

Single-instance: model.c

Multi-instance: None

modeloff

Note

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

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 ClassDeclarationDefinition
ExportedGlobalextern datatype identifier;

datatype identifier = value;

ImportedExternextern datatype identifier;External code
ImportedExternPointerextern datatype *identifier;External code
Constextern const datatype identifier;const datatype identifier = value;
Volatileextern volatile datatype identifier;volatile datatype identifier = value;
ConstVolatile extern const volatile datatype identifier;const volatile datatype identifier = value;
Define#define identifier valueNone
ImportedDefine#define identifier valueNone
ExportToFileextern datatype identifier;

datatype identifier = value;

ImportFromFileextern datatype identifier;External code
FileScopestatic 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;}
GetSetExternal codeExternal code
CompilerFlagNoneNone
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 ClassDeclarationDefinition
ExportedGlobalextern datatype identifier;

datatype identifier;

ImportedExternextern datatype identifier;External code
ImportedExternPointerextern datatype *identifier;External code
Volatileextern volatile datatype identifier;volatile datatype identifier;
ExportToFileextern datatype identifier;

datatype identifier;

ImportFromFileextern datatype identifier;External code
FileScopestatic 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;
GetSetExternal codeExternal 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 declarationHeaderFileLocation
AutoNone

model.h

InSourceFileNone

Define: model.h

Other storage class: No declaration generated

InSeparateHeaderFileNone

Header file specified by Data declaration filename, such as global.h

Any settingmy_header.hmy_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:

  • ImportedExtern

  • ImportedExternPointer

  • ImportedFromFile

  • Reusable (imported scope)

File packaging formatHeaderFileLocation
ModularNonemodel_private.h
CompactNone model.h
CompactWithDataFileNone model.h
Any settingmy_header.hmy_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:

  • ExportToFile

  • Const

  • Volatile

  • ConstVolatile

  • Localizable (global scope)

  • Reusable (exported scope)

Data definitionDefinitionFileOwnerLocation
AutoNoneNone or current model name

model.c

InSourceFileNoneNone or current model name

model.c

InSeparateSourceFileNoneNone or current model name

Header file specified by Data definition filename, such as global.c

Any settingmy_source.cNone or current model namemy_source.c
Any settingOther model nameNo definition generated when Use owner from data object for data definition placement is enabled

See Also

Topics