Main Content

Potential Differences Reporting

Generation of efficient C/C++ code from MATLAB® code sometimes results in behavior differences between the generated code and the MATLAB code. When you run your program, run-time error checks can detect some of these differences. By default, run-time error checks are:

  • Enabled for MEX code generated by using codegen (MATLAB Coder), fiaccel, or the MATLAB Coder™ app.

  • Disabled for standalone C/C++ code generated by using codegen (MATLAB Coder) or the MATLAB Coder app.

To help you identify and address differences before you deploy code, the code generator reports a subset of the differences as potential differences. A potential difference is a difference that occurs at run time only under certain conditions.

Addressing Potential Differences Messages

If the code generator detects a potential difference, it displays a message for the difference on the Potential Differences tab of the report. If you use the MATLAB Coder app to generate code, you can view the message in the Potential Differences tab of the app itself. To highlight the MATLAB code that corresponds to the message, click the message.

The presence of a potential difference message does not necessarily mean that the difference will occur when you run the generated code. To determine whether the potential difference affects your application:

  • Analyze the behavior of your MATLAB code for the range of data for your application.

  • Test a MEX function generated from your MATLAB code. Use the range of data that your application uses. If the difference occurs, the MEX function reports an error.

If your analysis or testing confirms the reported difference, consider modifying your code. Some potential differences messages provide a workaround. For additional information about some of the potential differences messages, see Potential Differences Messages. Even if you modify your code to prevent a difference from occurring at run time, the code generator might still report the potential difference.

The set of potential differences that the code generator detects is a subset of the differences that MEX functions report as errors. It is a best practice to test a MEX function over the full range of application data.

Disabling and Enabling Potential Differences Reporting for MATLAB Coder

By default, potential differences reporting is enabled for:

  • Code generation with the codegen command

  • The Check for Run-Time Issues step in the MATLAB Coder app

To disable potential differences reporting:

  • In a code configuration object, set ReportPotentialDifferences to false.

  • In the MATLAB Coder app, in the Debugging settings, clear the Report differences from MATLAB check box.

By default, potential differences reporting is disabled for the Generate code step and the code generation report in the MATLAB Coder app. To enable potential differences reporting, in the Debugging settings, select the Report differences from MATLAB check box.

Disabling and Enabling Potential Differences Reporting for Fixed-Point Designer

By default, potential differences reporting is enabled for code acceleration with fiaccel. To disable it, in a code acceleration configuration object, set ReportPotentialDifferences to false.

Related Topics