Storage Classes for Code Generation from MATLAB Code
If you have an Embedded Coder® license, you can use storage classes to control the declaration and definition of a global variable in the generated C/C++ code.
In the context of code generation, a storage class is a specification that determines the declaration and definition of a variable in the generated code. For code generation, the term storage class is not the same as the C language term storage class specifier.
Storage classes help you to integrate generated code with external code. You can make a generated variable visible to external code. You can also make variables declared in the external code visible to the generated code. For code generation from MATLAB® code, you can use storage classes with global variables only. The storage class determines:
The file placement of a global variable declaration and definition.
Whether the global variable is imported from external code or exported for use by external code.
To assign a storage class to a global variable, in your MATLAB code,
use the coder.storageClass
function.
Only when you use an Embedded Coder project or configuration
object for generation of C/C++ libraries or executables does the code
generator recognize coder.storageClass
calls.
The syntax for coder.storageClass
is:
coder.storageClass(global_name, storage_class)
global_name
is the name of a global variable,
specified as a character vector. global_name
must
be a compile-time constant.
storage_class
can be one of the following
values.
Storage Class | Description |
---|---|
'ExportedGlobal' |
|
'ExportedDefine' | Declares the variable with a |
'ImportedExtern' | Declares the variable as an |
'ImportedExternPointer' | Declares the variable as an |
Storage classes have these requirements and limitations:
Assign the storage class to a global variable in a function that declares the global variable. You do not have to assign the storage class in more than one function.
After you assign a storage class to a global variable, you cannot assign a different storage class to that global variable.
You cannot assign a storage class to a constant global variable.
A global variable with an
ExportedDefine
storage class must be a scalar but not a complex or multi-word scalar. The global variable must only be read and not written to in the code.
If you do not assign a storage class to a global variable, except
for the declaration location, the variable behaves like it has an 'ExportedGlobal'
storage
class. For an 'ExportedGlobal'
storage class, the
global variable is declared in the file
.
When the global variable does not have a storage class, the variable
is declared in the file entry_point_name
.h
.entry_point_name
_data.h