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

조회 수: 150(최근 30일)
MathWorks Support Team
MathWorks Support Team 2019년 2월 25일
답변: michael braverman 2021년 11월 9일 9:57
이 질문에 1명의 참여자가 플래그를 지정함
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?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2019년 4월 25일
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
John
John 2021년 2월 25일
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.

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Mayur Sathawane
Mayur Sathawane 2019년 5월 22일
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 2021년 11월 9일 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?

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by