[previous] MISRA-C:2004  Rule  6.4:  (Required) [next] Bit fields shall only be defined to be of type unsigned int or signed int.
Using int is implementation-defined because bitfields of type int can be either signed or unsigned. The use of enum, short or char types for bit fields is not allowed because the behaviour is undefined.

Example Code:


/* PRQA S 3205 ++ */

#include "misra.h"
#include "m2cmex.h"

extern S16 test_0604( void )
{
   typedef enum { A, B, C } e_t;

   struct  bitest
   {
      signed char     is_ctr : 3;     /* MISRA Violation */
      unsigned char   is_nul : 3;     /* MISRA Violation */
      int             is_set : 5;     /* MISRA Violation */
      signed int      is_key : 3;
      unsigned int    is_big : 3;
      unsigned long   is_dep : 3;     /* MISRA Violation */
      signed long     is_bad : 2;     /* MISRA Violation */
      e_t             is_enu : 2;     /* MISRA Violation */
      short           is_sh1 : 2;     /* MISRA Violation */
      signed short    is_sh2 : 2;     /* MISRA Violation */
      unsigned short  is_sh3 : 2;     /* MISRA Violation */
   } obj_0604;

   return 0;
}


QAC messages that encompass this guideline:

0634 [I] Bit-fields in this struct/union have not been declared explicitly as unsigned or signed.
0635 [E] Bit-fields in this struct/union have been declared with types other than int, signed int or unsigned int.


Related rules:

Rule  1.1 All code shall conform to ISO/IEC 9899:1990 C programming language, ISO 9899, amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2: 1996192
Rule  3.1 All usage of implementation-defined behaviour shall be documented.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents