MATLAB: How to prevent range checkings in the generated code for a stateflow model

Embedded Coder

How to prevent overflow condition checks in the generated code?
ex: Simple multiplication example
tmp = sf_fxptprecision_U.In1 * 10;
if (tmp > 255) {
tmp = 255;
}
sf_fxptprecision_Y.Out1 = (uint8_T)tmp;

Best Answer

The range checking can be eliminated by turning off the saturation on overflow setting in the chart.
1) Open the stateflow Chart
2) Right Click anywhere in the chart, select Properties
3) Turn off the overflow settings
The resultant code,
sf_fxptprecision_Y.Out1 = (uint8_T)(sf_fxptprecision_U.In1 * 10);