Code interface packaging
Package generated code interface as reusable or nonreusable functions or as a C++ class
Model Configuration Pane: Code Generation / Interface
Description
The Code interface packaging parameter specifies how the code generator packages generated C or C++ interface code.
Settings
Nonreusable function
(default) | Reusable function
| C++ class
Nonreusable function
Generates nonreusable code. The code generator allocates model data structures statically. Generated entry-point functions access the data structures directly.
This is the default setting when Language is set to
C
.Reusable function
Generates reusable, multi-instance code that is reentrant.
The generated
source file contains an allocation function that dynamically allocates model data for each instance of the model.model
.cThe generated code passes the real-time model data structure in, by reference, as an argument to entry-point functions.
The code generator exports the real-time model data structure in the
header file.model
.h
Selecting
Reusable function
:Enables the Multi-instance code error diagnostic parameter.
Does not change the code generated for function-call subsystems.
If the System target file parameter is set to an ERT-based system target file:
This
Reusable function
setting is not supported if the model is configured with a service code interface.Selecting
Reusable function
enables parameters Use dynamic memory allocation for model initialization and Pass root-level I/O as.Use Use dynamic memory allocation for model initialization to control whether to generate an allocation function.
Use Pass root-level I/O as to control how root-level input and output arguments are passed to the reusable model entry-point functions. You can include the arguments in the real-time model data structure that is passed to the functions, pass the arguments individually, or pass the arguments as references to input and output structures.
You can select
Reusable function
when generating a staticert_main.c
module, if you do the following:Select the Use dynamic memory allocation for model initialization parameter.
Set the Pass root-level I/O as parameter to
Part of model data structure
.
You cannot select
Reusable function
if you:Customize the
model_step
function prototype of a model that passes root-level I/O as a structure reference or part of the model data structure.Select subsystem block parameter Function with separate data.
Use a subsystem that:
Has multiple ports that share source.
Has a port that is used by multiple instances of the subsystem and has different sample times, data types, complexity, frame status, or dimensions across the instances.
Has output marked as a global signal.
For each instance contains identical blocks with different names or parameter settings.
C++ class
Generates a C++ class interface for the model. The generated interface encapsulates required model data into C++ class attributes and model entry point functions into C++ class methods.
To enable this value, set the Language parameter to
C++
. When Language is set toC++
, this value is the default setting.For a model configured with a service code interface, this parameter setting is not relevant and, therefore, is not supported.
Selecting
C++ class
enables the Multi-instance code error diagnostic parameter.
Tips
The code generator exports entry-point functions in
. To call the entry-point functions from user-written code, add anmodel
.h#include
directive to the code.model
.hWhen you select
Reusable function
, the code generator generates a pointer to the real-time model object (
).model
_MWhen you select
Reusable function
and set the Multi-instance code error diagnostic parameter toWarning
orNone
, the code generator might generate code that compiles but is not reentrant. For example, if a signal, a DWork structure, or parameter data has a storage class other thanAuto
, the code generator produces global data structures.
Recommended Settings
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No impact |
Efficiency | Reusable function or C++ class |
Safety precaution | No impact |
Programmatic Use
Parameter: CodeInterfacePackaging |
Type: character vector |
Value: 'C++ class' | 'Nonreusable function' | 'Reusable function' |
Default: 'Nonreusable function' if TargetLang is set to 'C' ; 'C++ class' if TargetLang is set to 'C++' |
Version History
Introduced in R2014a
See Also
Topics
- Model Configuration Parameters: Code Generation Interface
- Configure Generated C Function Interface for Model Entry-Point Functions
- Generate Reentrant Code from Top Models
- Combine Code Generated for Multiple Models or Multiple Instances of a Model
- Generate C++ Class Interface to Model or Subsystem Code
- Interactively Configure C++ Interface (Embedded Coder)
- Generate Reentrant Code from Subsystems
- S-Functions for Code Reuse
- Static Main Function Module (Embedded Coder)
- Configure Generated C Function Interface for Model Entry-Point Functions (Embedded Coder)
- Generate Modular Function Code for Nonvirtual Subsystems (Embedded Coder)
- Generate Component Source Code for Export to External Code Base (Embedded Coder)