Disable Support for Integer Overflow or Non-Finites

The code generator produces supporting code for the following situations:

  • The result of an integer operation falls outside the range that a data type can represent. This situation is known as integer overflow.

  • An operation generates non-finite values (inf and NaN). The supporting code is contained in the files rt_nonfinite.c, rtGetInf.c, and rtGetNaN.c (with corresponding header files).

If you know that these situations do not occur, you can suppress generation of the supporting code. You therefore reduce the size of the generated code and increase its speed. However, if one of these situations occurs, it is possible that the generated code does not match the behavior of the original MATLAB® code.

Disable Support for Integer Overflow

You can use the MATLAB Coder™ app or the command-line interface to disable support for integer overflow. When you disable this support, the overflow behavior of your generated code depends on your target C compiler. Most C compilers wrap on overflow.

  • Using the app:

    1. To open the Generate dialog box, on the Generate Code page, click the Generate arrow .

    2. Click More Settings.

    3. On the Speed tab, clear Saturate on integer overflow.

  • At the command line:

    1. Create a configuration object for code generation. Use coder.config with arguments 'lib', 'dll', or 'exe' (depending on your requirements). For example:

      cfg = coder.config('lib');

    2. Set the SaturateOnIntegerOverflow property to false.

      cfg.SaturateOnIntegerOverflow = false;

Disable Support for Non-Finite Numbers

You can use the MATLAB Coder app or the command-line interface to disable support for non-finite numbers(inf and NaN).

  • Using the app:

    1. To open the Generate dialog box, on the Generate Code page, click the Generate arrow .

    2. Set Build type to Source Code, Static Library, Dynamic Library, or Executable (depending on your requirements).

    3. Click More Settings.

    4. On the Speed tab, clear the Support non-finite numbers check box.

  • At the command line:

    1. Create a configuration object for code generation. Use coder.config with arguments 'lib', 'dll', or 'exe' (depending on your requirements). For example:

      cfg = coder.config('lib');

    2. Set the SupportNonFinite property to false.

      cfg.SupportNonFinite = false;

Was this topic helpful?