[previous] 0457 [next] [C] The address-of operator '&' cannot be applied to a bit-field.
Constraint violations REFERENCE - ISO:C90-6.3.3.2 Address and Indirection Operators - Constraints

This is a constraint error

It might be possible to take the address of the struct/union which contains the bit-field, but it is never possible to take the address of a bit-field itself. A bit-field, by definition, can occupy part or all of a byte or word. The & (address of) operator returns the addressable location of an object in terms of bytes and so cannot specify exactly the bit-field location within a byte or word. For example:


/*PRQA S 2211,3198,3199,3203,3621 ++*/

struct flags {
   unsigned int hi:1;
   unsigned int lo:1;
   unsigned int ins:1;
   unsigned int ovr:1;
};

int main(void)
{
   struct flags f;
   int *ip;
   unsigned int i;

   f.hi = 0;
   f.lo = 0;
   f.ins = 0;
   f.ovr = 0;


   ip = &(f.hi);           /* Message 0457 */
   ip = &f.lo;             /* Message 0457 */

   i = f.ins;

   return 0;
}


MISRA C:2012 Rules applicable to message 0457:

Rule-1.1  (Required) The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits


QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents