Main Content


Model data and interface configuration for C++ code generation

Since R2021a


A code mappings object and related functions enable you to configure C++ code generation for data and functions of a Simulink model. For model data elements, code mappings associate data elements with configurations that consist of a storage class and storage class properties. For functions, code mappings associate entry-point functions with configurations that consist of a function customization template. Reduce the effort of preparing a model for C++ code generation by specifying default configurations for categories of data elements and functions across a model. Override default configurations by configuring data elements or functions individually. For smaller models, you can choose to configure each data element and function individually.


When you select the Embedded Coder app from the Apps tab in the Simulink® Editor, the app creates a coder.mapping.api.CodeMappingCPP object if code mappings do not already exist. The app creates code mappings based on code customization settings stored in the model active configuration set object. The configuration set object can specify memory sections for data and functions.

Access a coder.mapping.api.CodeMappingCPP object programmatically by using the coder.mapping.utils.create or coder.mapping.api.get functions.

Object Functions

findGet model elements for the category of model code mappings
getClassNameGet class name of model
setClassNameSet class name of model
getClassNamespaceGet class namespace for a model
setClassNamespaceSet class namespace of model
getDataGet code mapping configuration for model data
setDataConfigure model data for C++ code generation
getFunctionGet code configuration from code mappings for model function
setFunctionSet code mapping information for model function


collapse all

Open the model CppClassRateBased, and create the environment for configuring model data and functions for code generation by using the coder.mapping.utils.create function.


After calling coder.mapping.utils.create, use calls to other functions listed under Object Functions to configure aspects of code generation for model interface elements.

Version History

Introduced in R2021a