Dir 4.8 if struct is only visible through a function declaration - 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 if struct is only visible through a function declaration (/showthread.php?tid=1452) |
Dir 4.8 if struct is only visible through a function declaration - LMende - 29-08-2018 Hi there, I humbly ask for help with compliance to Dir 4.8. (Borrowing from cxlin, thx) Code: /* def.h */ A pointer to SomeType is only visible through the included other.h where the usetype function is declared. Is the implementation of no-use.c compliant with Dir 4.8 or not? Re: Dir 4.8 if struct is only visible through a function declaration - dg1980 - 30-08-2018 First let me quote MISRA C 2012 chapter 6.1: Quote:A directive is a guideline for which it is not possible to provide the full description necessary to perform a check for compliance Also, it is classified advisory, so it would not require a formal deviation. The answer to your question depends on whether other translation units in your project include def.h and use struct SomeType directly (creating a variable, accessing members etc.). In that case, the opaque technique described in DIR 4.8 does not apply. Re: Dir 4.8 if struct is only visible through a function declaration - misra-c - 16-10-2018 The following discussion assumes that the prototype for usetype is 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 */ Whether a particular translation unit violates directive 4.8 does not depend on how "struct SomeType" is used in other translation units. |