Data Type Replacement of Boolean_T into bool (Matlab R2020b)

조회 수: 35 (최근 30일)
Eduardo Wiputra
Eduardo Wiputra 2023년 9월 1일
편집: Akshat 2023년 9월 22일
We are currently doing a project using Matlab R2020b. We are trying to find a way to ensure that boolean data type in Simulink is translated directly into bool data type that is available natively in C/C++. We know that this option is available in R2023a (https://www.mathworks.com/help/ecoder/ug/control-data-type-names-in-generated-code.html) when we set `Use C data types with fixed-width integers`. Is there such an option or workaround in R2020b which allows us to do that?
The motivation for ths is because our static analysis checker indicates a warning because we are converting a boolean quantity into unsigned char, and we want to see if we can get rid of that warning.
The following is the snippet of codes (modified to illustrate the point) that show the typedef and our simple assignment/calculation/comparison. Specifically, note that the BOOLEAN data type is essentially mapped to uint8_T data type and we would like to keep it as bool when possible. Otherwise, the static analysis will complain because we are assigning a boolean quantity (right-hand side of equal sign) into a uint8 quantity (left-hand side of equal sign) in the last line.
#define TEN_PERCENT_SLOPE 10.0F
typedef unsigned char uint8_T;
typedef unsigned char boolean_T;
typedef boolean_T BOOLEAN;
float rollDeg = 10.0f;
float localGain = tanf(0.0174532924F * fabsf(rollDeg)) * 100.0F;
BOOLEAN yOutput2_pitchBelowTenPercent = (localGain < TEN_PERCENT_SLOPE);
Thank you for your help!

답변 (1개)

Akshat
Akshat 2023년 9월 19일
편집: Akshat 2023년 9월 22일
I understand that you are seeking a method to directly translate boolean data types in Simulink into bool data types in the generated code. To address this requirement, you can refer to the following documentation pages for detailed information and guidance:
I hope this helps.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by