Clear Filters
Clear Filters

Why is the preprocessor check #if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) ) being generated in private.h?

37 views (last 30 days)
In the generated code for my model, I have noticed that the following code is generated in the "model_private.h" file:
#if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) ) #error Code was generated for compiler with different sized uchar/char. \ Consider adjusting Test hardware word size settings on the \ Hardware Implementation pane to match your compiler word sizes as \ defined in limits.h of the compiler. Alternatively, you can \ select the Test hardware is the same as production hardware option and \ select the Enable portable word sizes option on the Code Generation > \ Verification pane for ERT based targets, which will disable the \ preprocessor word size checks. #endif
Why is this code being generated?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Aug 2024
Edited: MathWorks Support Team on 20 Aug 2024
This code is included when there are fixed-point data types in the model and fixed-point word size checks are enabled. The limit for each type is the max and min values that can be represented by the type. The header file is included to perform some checks on the target (e.g., because fixpoint slope/bias can cause overflow).
The recommended workflow is to set the correct values of the bits in the "Configuration Parameters" -> "Hardware Implementation" -> Device Details section based on the values defined by the compiler in the limits.h file. You can avoid these checks completely in the following way if the customer does not want these checks:
From MATLAB R2024a, this option is available directly as checkbox in 'Configuration Parameters' -> 'Code Generation' -> 'Interface' -> 'Advanced parameters' -> 'Suppress generation of fixed-point word size checks'
From MATLAB R2017a onwards you can add a TLC option which will ensure that the Fixed Point Word Size checking code will not be generated. To use this option, navigate to 'Configuration Parameters' -> 'All Parameters' tab. Then search for "TLC Options" and add the following text to the TLC options check box  "-aRemoveFixptWordSizeChecks=1".
For older versions of MATLAB (before R2017a), you can disable these #define checks by setting the 'TargetPreprocMaxBitsSint' and 'TargetPreprocMaxBitsUint' to a value of '0'. To do this, navigate to 'Configuration Parameters' and click on the 'List' tab on the top of the dialog box. Then search for the above two parameters and set them to '0'. If we generate code then the #define checks will be disabled by #if 0 statements encapsulating the above statements.

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!