Main Content

Code interface packaging

Description

Select the packaging for the generated C or C++ code interface.

Category: Code Generation > Interface

Settings

Default: Nonreusable function if parameter Language is set to C; C++ class if Language is set to C++

C++ class

Generate a C++ class interface to model code. The generated interface encapsulates required model data into C++ class attributes and model entry point functions into C++ class methods.

Nonreusable function

Generate nonreusable code. Model data structures are statically allocated and accessed by model entry point functions directly in the model code.

Reusable function

Generate reusable, multi-instance code that is reentrant, as follows:

  • For a GRT-based model, the generated model.c source file contains an allocation function that dynamically allocates model data for each instance of the model. For an ERT-based model, you can use parameter Use dynamic memory allocation for model initialization to control whether an allocation function is generated.

  • The generated code passes the real-time model data structure in, by reference, as an argument to model_step and the other model entry point functions.

  • The real-time model data structure is exported with the model.h header file.

For an ERT-based model, you can use parameter Pass root-level I/O as to control how root-level input and output arguments are passed to the reusable model entry-point functions. They can be included in the real-time model data structure that is passed to the functions, passed as individual arguments, or passed as references to an input structure and an output structure.

Tips

  • Entry points are exported with model.h. To call the entry-point functions from handwritten code, add an #include model.h directive to the code.

  • When you select Reusable function, the code generator generates a pointer to the real-time model object (model_M).

  • When you select Reusable function, the code generator can generate code that compiles but is not reentrant. For example, if a signal, DWork structure, or parameter data has a storage class other than Auto, global data structures are generated.

Dependencies

  • The value C++ class is available only if parameter Language is set to C++.

  • Selecting Reusable function or C++ class enables parameter Multi-instance code error diagnostic.

  • For an ERT-based system target file, selecting Reusable function enables parameters Pass root-level I/O as and Use dynamic memory allocation for model initialization.

  • To enable parameter Classic call interface, select Nonreusable function.

  • For an ERT-based system target file, selecting C++ class enables the following model configuration controls for customizing the model class interface:

    • Configure C++ Class Interface button

    • Data Member Visibility/Access Control subpane

    • Parameters Generate destructor and Use dynamic memory allocation for model block instantiation

  • For an ERT-based system target file, you can select Reusable function with the static ert_main.c module, if you do the following:

    • Set parameter Pass root-level I/O as to Part of model data structure.

    • Select parameter Use dynamic memory allocation for model initialization.

  • For an ERT-based system target file, you cannot select Reusable function if you are:

    • Customizing the model_step function prototype

    • Selecting subsystem block parameter Function with separate data

    • Using 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

  • Selecting Reusable function does not change the code generated for function-call subsystems.

Command-Line Information

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++'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyReusable function or C++ class
Safety precautionNo impact

See Also

Related Topics