Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor edit

...

The assertion fails if long long has less than twice the width of int. The purpose of the The  UWIDTH() macro and the function popcount() is function are explained in INT19-C. Correctly compute integer widths.  The following  following portable compliant solution can be used for implementations on any conforming implementation, including those where this assertion fails:

...

The C Standard, 6.5.7 paragraph 4 [ISO/IEC 9899:2011], states

...

In almost every case, an attempt to shift by a negative number of bits or by more bits than exist in the operand indicates a bug (logic error). These issues are covered by INT34-C. Do not shift a negative number of bits or more bits than exist in the operand.

Noncompliant Code Example

This noncompliant code example can result in an unrepresentable value. 

...

Compliant Solution

This compliant solution eliminates the possibility of overflow resulting from a left-shift operation:

...