16-10-2018, 10:41 AM
The following discussion assumes that the prototype for usetype is
The translation unit for no-use.c never accesses the members of "struct SomeType" and therefore the example is not compliant with directive 4.8. To be compliant with this rule another header file should be created.
opaque_def.h would be used in those translation units which did not dereference the pointer "struct SomeType *" whereas def.h would be used in those translation units which did dereference the pointer.
Whether a particular translation unit violates directive 4.8 does not depend on how "struct SomeType" is used in other translation units.
Code:
extern void usetype(struct SomeType* p);
The translation unit for no-use.c never accesses the members of "struct SomeType" and therefore the example is not compliant with directive 4.8. To be compliant with this rule another header file should be created.
Code:
/* opaque_def.h */
typedef struct SomeType *pSomeType;
/* other.h */
extern void usetype(pSomeType p);
/* no-use.c */
#include opaque_def.h
#include other.h
/* Do something. But no use of SomeType at all. */
Whether a particular translation unit violates directive 4.8 does not depend on how "struct SomeType" is used in other translation units.
Posted by and on behalf of the MISRA C Working Group