MISRA Discussion Forums
Dir 4.8 2 struct pointers in a Translation unit - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 7.4 Code design (https://forum.misra.org.uk/forumdisplay.php?fid=181)
+---- Thread: Dir 4.8 2 struct pointers in a Translation unit (/showthread.php?tid=1145)



Dir 4.8 2 struct pointers in a Translation unit - misra-c - 13-02-2015

What happens if there are 2 pointers to a struct/union in a translation unit. One which accesses the details of the struct/union and the other does not. For Example:
File1.h
Code:
struct X { int32_t i1 };
  typedef struct X * ptrX;
  extern  void use_ptrX ( ptrX p );

File1.c
Code:
void fn ( ptrX a, ptrX b )
  {     /* no reference to a->i1 in translation unit  - does the type of "a" need to be opaque? */
     use_ptrX ( a );
     use_int32 ( b -> i1 ) ;
}



Re: Dir 4.8 2 struct pointers in a Translation unit - misra-c - 13-02-2015

The implementation of an object need only be hidden if all pointers to that type in a translation unit are never dereferenced and there are no other reasons for the internal details of the structure/union to be known.

In the above example "ptrX a" is complaint, because member “i1” from “struct X” is accessed elsewhere in the translation unit.