TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
ASML C Coding Standard
Search

Rule:  6.5.aChecked automatically with code checker

Synopsis:Bitwise operations shall only be applied on operands of unsigned type.
Language:C
Severity Level:4
Category:Expressions


Description:

Justification

Bitwise operations on operands of signed type may result in undefined behavior and implementation defined behavior.

Example

int mask = 0x80000000;
unsigned int u = mask >> 24; /* WRONG */

Note

The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a non-negative value, the value of the result is the integral part of the quotient of E1 / 2E2. If E1 has a signed type and a negative value, the resulting value is implementation defined.