The Motor Industry Software Reliability Association (MISRA®) has established “Guidelines for the Use of the C Language in Critical Systems” (MISRA C®). When you generate code from MATLAB® code, if you have Embedded Coder®, you can configure certain code generation parameters to increase the likelihood of generating C and C++ code that comply with the MISRA C:2012 and MISRA C++:2008 guidelines.
The following describes the separate command line and app workflows.
Create an Embedded Coder code generation configuration object.
cfg = coder.config('lib', 'ecoder', true);
Set the properties listed in the table to the values for improved MISRA compliance.
|Property||Value for Improved MISRA Compliance|
Any valid namespace name for C++
To set these properties in one step, use
Alternatively, set properties individually. For example:
cfg.CastingMode = 'Standards';
CppNamespace property is unset, and the
TargetLang property is
coder.setupMISRAConfig sets the
property to a default character vector,
'Codegen'. Modify this
value to a namespace name that is particular to your project.
Pass the configuration object to
codegen by using the
codegen myFunction -config cfg ...
On the Generate Code page, set Build
Dynamic Library, or
Click More Settings.
Click MISRA Compliance.
The app displays the settings that might impact MISRA compliance.
To set all of these settings to the recommended values, click Set to Recommended Values.
To modify an individual setting, click All Settings, and then search for the setting.
By default, the C++ code that you generate uses a custom type definition for
bool to maximize compatibility with certain precompiled libraries. This
custom type definition can cause violations for MISRA C++:2008 Rule 5-0-13 and Rule 5-3-1.
To use the built-in
bool type in generated C++ code, and avoid these
violations, change the Hardware Board setting in the configuration
MATLAB Host Computer. To see how to change this setting in the App, see
Access Hardware Implementation Properties with a Dialog Box. For example, for
code generation and build on a 64-bit Windows® platform, change the Hardware Board to
- Select device below, and then set Device vendor to
Intel and Device type to
 MISRA and MISRA C are registered trademarks of HORIBA MIRA Ltd., held on behalf of the MISRA Consortium.