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

146 views (last 30 days)
This question was flagged by Walter Roberson
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 25 Apr 2019
The above code is being generated because a signal or block with a fixed point data type is being used in your model. Please refer to the link for more details.
  1 Comment
John
John on 25 Feb 2021
This code construct is in error for 2 reasons and should be removed/updated from the templates.
1) The LONG and ULONG types are not used in the portable datatypes that the generator creates under the ERT. Where a long type is used, it is not considered to be a specific size.
/*=======================================================================*
* Fixed width word size data types: *
* int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
* uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
* real32_T, real64_T - 32 and 64 bit floating point numbers *
*=======================================================================*/
typedef signed char int8_T;
typedef unsigned char uint8_T;
typedef short int16_T;
typedef unsigned short uint16_T;
typedef int int32_T;
typedef unsigned int uint32_T;
typedef float real32_T;
typedef double real64_T;
2) Why isn't the fixed size type variables used from <stdint.h> instead of Matlab recreating this? This section ensures that I cannot use the same generated code on separate machine architectures even though the source code is actually identical.

Sign in to comment.

More Answers (2)

Mayur Sathawane
Mayur Sathawane on 22 May 2019
Change below porperty in model configuration,
'ERTFilePackagingFormat' to 'Modular', (Code Generation --> Code Placement --> Code Packaging)
This will include model_private.h in code instead.

michael braverman
michael braverman on 9 Nov 2021 at 9:57
Yeah, the question is though why sometimes I see this code and sometimes not, when in both cases the signals and data types are essentially similar?

Tags

No tags entered yet.

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!