Data Type Replacement of Boolean_T into bool (Matlab R2020b)
17 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Akshat
on 19 Sep 2023
Edited: Akshat
on 22 Sep 2023
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.
0 Comments
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!