Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.BITFIELD.SIGNED

Length of a named signed bit-field is less than 2.

MISRA C 2012 Rule 6.2: Single-bit named bit fields shall not be of a signed type

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Rationale

According to the C99 Standard Section 6.2.6.2, a single-bit signed bit-field has a single (one) sign bit and no (zero) value bits. In any representation of integers, 0 value bits cannot specify a meaningful value.

A single-bit signed bit-field is therefore unlikely to behave in a useful way and its presence is likely to indicate programmer confusion.

Although the C90 Standard does not provide so much detail regarding the representation of types, the same considerations apply as for C99.

Note: this rule does not apply to unnamed bit fields as their values cannot be accessed.

Signed bit-field has length 1.

MISRA-C 2004 Rule 6.5 (required): Bit fields of signed type shall be at least 2 bits long

This rule is also covered by MISRA.BITFIELD.SIGNED.UNNAMED.

A signed bit field of 1 bit length is not useful.

MISRA-C++ 2008 Rule 9-6-4 (required): Named bit-fields with signed integer type shall have a length of more than one bit

Rationale

The values which may be represented by a bit-field of length one may not meet developer expectations. Anonymous signed bit-fields of any length are allowed.

Example

struct S
{
   signed int    a : 1;  // Non-compliant
   signed int      : 1;  // Compliant
   signed int      : 0;  // Compliant
   signed int    b : 2;  // Compliant
   signed int      : 2;  // Compliant
};