Signed right shift
(-logical-signed-right-shift
)
Specify how to treat the sign bit for logical right shifts on signed variables
Description
Choose between arithmetic and logical shift for right shift operations on negative values.
This option does not modify compile-time expressions. For more details, see Limitation.
Set Option
User interface (desktop products only): In your project configuration, the option is on the Target & Compiler node.
User interface (Polyspace Platform, desktop products only): In your
project configuration, the option is on the Build tab on the
Target & Compiler node. This option is renamed to
Shift right on signed integers as arithmetic shift
in Polyspace
platform user interface. See Shift right on signed integers as arithmetic
shift
Command line and options file: Use the option
-logical-signed-right-shift
. See Command-Line Information.
Why Use This Option
The C99 Standard (sec 6.5.7) states that for a right-shift operation
x1>>x2
, if x1
is signed and has negative
values, the behavior is implementation-defined. Different compilers choose between
arithmetic and logical shift. Use this option to emulate your compiler.
Settings
Default:
Arithmetical
Arithmetical
The sign bit remains:
(-4) >> 1 = -2 (-7) >> 1 = -4 7 >> 1 = 3
Logical
0 replaces the sign bit:
(-4) >> 1 = (-4U) >> 1 = 2147483646 (-7) >> 1 = (-7U) >> 1 = 2147483644 7 >> 1 = 3
Limitation
In compile-time expressions, this Polyspace® option does not change the standard behavior for right shifts.
For example, consider this right shift expression:
int arr[ ((-4) >> 20) ];
(-4) >> 20
is evaluated at
compilation time. Logically, this expression is equivalent to 4095. However, arithmetically,
the result is -1. This statement causes a compilation error (arrays cannot have negative size)
because the standard right-shift behavior for signed integers is arithmetic.Command-Line Information
When using the command line, arithmetic is the default computation mode. When this option is set, logical computation is performed.
Parameter:
-logical-signed-right-shift |
Default: Arithmetic signed right shifts |
Example (Bug Finder):
polyspace-bug-finder -logical-signed-right-shift |
Example (Code Prover):
polyspace-code-prover -logical-signed-right-shift |
Example (Bug Finder Server): polyspace-bug-finder-server -logical-signed-right-shift |
Example (Code Prover Server):
polyspace-code-prover-server -logical-signed-right-shift |