[previous] MISRA-C:2004  Rule  20.6:  (Required) [next] The macro offsetof, in library <stddef.h>, shall not be used.
Use of this macro can lead to undefined behaviour when the types of the operands are incompatible or when bit fields are used.

Example Code:


/* PRQA S 2983,3203 ++ */

#include <stddef.h>
#include "misra.h"
#include "m2cmex.h"


extern S16 test_2006( void )
{
   struct stag
   {
      S32  a;
      F64  b;
   } s;

   size_t p;

   s.a = 1;
   s.b = 0.0;

   p = offsetof( struct stag, b );      /* MISRA Violation */

   return 0;
}






QAC messages that encompass this guideline:

5120 The macro offsetof, in library <stddef.h>, shall not be used.



(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