Main Content

Allow right shifts on signed integers

Allow right bitwise shifts on signed integers

Model Configuration Pane: Code Generation / Code Style

Description

Specify whether to allow signed right bitwise shifts in the generated C/C++ code. Some coding standards, such as MISRA, do not allow bitwise operations on signed integers. Clearing this option increases the likelihood of generating MISRA-C:2004 compliant code.

Settings

on (default) | off

Default: on

On

Generate code that uses right bitwise shifts on signed integers.

For example, when you select this option, right shifts appear in the generated code.

i >>= 3

Off

Do not allow right shifts on signed integers. Clearing this option supports MISRA C® compliance.

For example, when you clear this option, right shifts are replaced with a function call.

i = asr_s32(i, 3U);

Examples

expand all

Compare how the generated code implements right bitwise shifts of signed integers when you set Allow right shifts on signed integers to different values.

Here is generated code that generated using the default Allow right shifts on signed integers value on. Right shifts appear in the generated code:

i >>= 3

Here is the same code generated with Allow right shifts on signed integers set to off. Right shifts are replaced by a function call:

i = asr_s32(i, 3U);

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

Programmatic Use

Parameter: EnableSignedRightShifts
Type: character vector
Value: 'on' | 'off'
Default: 'on'

Version History

Introduced in R2015b