Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - 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: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement (/showthread.php?tid=1493) |
Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - chenzhuowansui - 29-06-2019 Hi, Given the following case: Code: static inline uint32_t test(void) i wonder if we could take the above case as compliant, as we cannot have variable declaration and return value in assembly. Thanks Re: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - chenzhuowansui - 19-08-2019 Could anyone help clarify it? thanks Re: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - chenzhuowansui - 19-08-2019 Not sure why this content was deledted and cannot be seen any longer, i just re-posted it here. Could anyone help clarify it? thanks static inline uint32_t test(void) { uint32_t tmp; __asm__ __volatile__( "mrc p15, 0, %0, c1, c0, 2\n\t" : "=r" (tmp) ); return tmp; } i wonder if we could take the above case as compliant, as we cannot have variable declaration and return value in assembly. Re: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - misra-c - 06-09-2019 Thank you for your question. The MISRA-C Working Group will consider this question at their next meeting in October Re: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - chenzhuowansui - 11-10-2019 Any update on this question? thanks Re: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - chenzhuowansui - 15-11-2019 Hi there, may i know if there is any conclusions for this issue? Thanks Re: Question about Dir 4.3 when a static function contains only variable declaration, asm and return statement - misra-c - 27-11-2019 Directive 4.3 states that the assembly language instruction shall be "encapsulated and isolated". This guideline is a directive rather than a rule, which means that the phrase "isolated" should not be taken as fully defined and may be interpreted in different ways by different projects. The intention is that there should be minimal C code within the enclosing macro or function. In particular, the intention is that there should be no C language statements which have effects in the abstract machine. For example: * expression statements * selection statements * iteration statements The MISRA-C working group would consider that a function that contains only declarations and a return statement in addition to the assembler code instructions is acceptable. RE: Question about Dir 4.3 when a static function contains only variable declaration, ... - chenzhuowansui - 27-04-2022 we have an additional question here, what about the following example, is it still acceptable: Code: static inline uint32_t test(void) { please help clarify for this case, many thanks in advance! RE: Question about Dir 4.3 when a static function contains only variable declaration, ... - misra-c - 08-02-2023 The whole point of the Directive is to encapsulate the assembly language... therefore any additional code (including a +1) is no longer encapsulating the assembler. While this may be considered a trivial matter, any other position results in salami-slicing - if X is OK what about X+Y - and makes diagnosis less decidable. You may, of course, choose to deviate, with the support of your assessor |