Local variables are getting generated after code generation using embedded coder and if statement expression is not Boolean type throwing an error after running polyspace

3 次查看(过去 30 天)
An Image shown below in which guard condition is mentioned whose if statement is non compitant as per MISRA C 2012 Rule 14.4
As per Rule if statement should have boolean type expression.

采纳的回答

Akshat Dalal
Akshat Dalal 2025-1-23
Hi Mukund,
I faced a similar issue and it was occuring because the underlying data type of boolean_t generated by Embedded coder seems to unsigned char. I was able to get around this by creating an alias for boolean and changing its base type to int8, which changes the underlying data type to signed char.
  1. Create a Simulink.AliasType in the base workspace named boolean_t
  2. Set it's base type to be of type int8
  3. Reference boolean_t in the data type replacement for boolean under the Configuration parameters -> Code Generation -> Data Type Replacement pane
This should remove the violations while keeping the generated code same as before. The change can be observed in the rtwtypes.h file which gets generated.
Hope this helps. Thanks!

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by