Main Content

Check Code Generation Assumptions

The code generator implements assumptions that depend, for example, on the hardware implementation settings for your model. It is important to check that the assumptions are valid for your target hardware. Use the buildStandaloneCoderAssumptions (Embedded Coder) function to create an application that performs assumption checks on your target hardware.

When you configure your model, try to specify hardware implementation and build configuration settings that match your target hardware. Then, to check code generator assumptions for your target hardware, use this workflow:

  1. With GenerateReport set to 'on', build (Ctrl+B) your model.

  2. To view the list of code generator assumptions that you can check, open the code generation report and click the Coder Assumptions link.

    For more information, see Coder Assumptions List.

  3. Run buildStandaloneCoderAssumptions, which uses the generated code in the build folder to create an application that runs code generation assumption checks.

  4. Download the application onto the target hardware or target environment, and then run the application.

  5. While the application runs, use a debug tool to view check results that are in a data structure.

Check Code Generator Assumptions for Development Computer

If the target hardware is, for example, your Windows® development computer, you can use Microsoft® Visual Studio® to run and debug the application:

  1. To open a model, in the Command Window, enter:

    openExample('ecoder/SILPILVerificationExample', ...

  2. In the Model Configuration Parameters dialog box, in the Hardware Implementation pane, specify settings to match the target hardware. For example, for a 64-bit Windows computer specify these parameter settings:

    • Device vendor –– Intel

    • Device type –– x86-64 (Windows 64)

  3. Clear model configuration parameter Enable portable word sizes.

  4. Build the model (Ctrl+B).

  5. To view the list of code generator assumptions, open the code generation report and click the Coder Assumptions link.

  6. From the Command Window, in the working folder, run:

    In the build folder, the function creates the coderassumptions\standalone subfolder, which contains the target application, SILTopModel_ca.

  7. Open Microsoft Visual Studio and select File > Open > Project/Solution

  8. Using the Open Project dialog box, navigate to the coderassumptions\standalone subfolder and select SILTopModel_ca. Then, click Open.

  9. Select File > Open > File. Using the Open File dialog box, select coderassumptions\standalone\SILTopModel_ca.c

  10. At the return statement, insert a break point.

  11. Select Debug > Start Debugging.

  12. To verify code generator assumptions, use a Watch window to inspect the Results data structure:

    1. In the SILTopModel_ca.c code, right-click Results.

    2. From the context menu, select Add Watch.

The variables in the data structure contain:

  • Check outcomes (TestResults)

  • Target hardware truths (ActualValues)

  • Code generator assumptions (ExpectedValues)

For example, if the code generator assumption for bitsPerChar is accurate, you see the CA_PASS value in the status variable.

Coder Assumptions List

The contents section of the code generation report has a link to the Coder Assumptions page. The page provides a list of:

  • Code generation assumptions that you can check

  • Expected results for the assumption checks

This table describes the labels that you see in the list.

CategoryLabelAssumption You Can Check
C/C++ Language Configuration for Target Hardware or Development Computer


Number of bits per char (ProdBitPerChar)


Number of bits per short (ProdBitPerShort)


Number of bits per int (ProdBitPerInt)


Number of bits per long (ProdBitPerLong)


Size of float (Only if PurelyIntegerCode is 'off')


Size of double (Only if PurelyIntegerCode is ‘off’)


Number of bits per pointer (ProdBitPerPointer)


Number of bits per size_t (ProdBitPerSizeT)


Number of bits per ptrdiff_t (ProdBitPerPtrDiffT)


Byte ordering (ProdEndianess)

Shift right for signed integer is arithmetic shift

Sign bit behavior (ProdShiftRightIntArith)

Signed integer division rounds to

Rounding behavior for integer division (ProdIntDivRoundTo)

C/C++ Language Standard

Initial value of a global integer variable and dynamically allocated memory is zero

Zero initialization of memory (ZeroExternalMemoryAtStartup, ZeroInternalMemoryAtStartup, and GenerateAllocFcn)

Floating-Point Numbers

Flush-to-zero computed subnormal values (FTZ)

Flush-to-zero subnormal number processing

Flush-to-zero incoming subnormal values (DAZ)

Denormals-are-zero subnormal number processing

See Also

(Embedded Coder)

Related Topics