Rule 2.1 - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.2 Language Extensions (https://forum.misra.org.uk/forumdisplay.php?fid=29) +---- Thread: Rule 2.1 (/showthread.php?tid=217) |
Rule 2.1 - nikunj - 16-02-2006 What are the possible scenarios in which Rule 2.1 will be violated? Rule allows for Macros, C-functions and Assembly functions. If any assembly code is used directly it will be reported as an compliler error for undefined identifier etc. - misra-c - 27-04-2006 C statements and assembler statements should not co-exist in a function unless the assembler is encapsulated in a macro. The following example violates this rule. Code: static void foo ( void ) - nikunj - 03-05-2006 Do the following code snippets violate Rule 2.1? 1. macro encapsulation: #pragma asm MOV A,B .... .... #pragma endasm 2.function call asm(\"CLI\"); or move(\"MOV A,B\"); Also statements like asm{ \"CLI\" }; seem to be compiler specific. What are the other possible ways of violating this rule (compiler specific/not specific). Also, please can you give examples where the rule is not violated. - lv - 05-05-2006 Quote:Also, please can you give examples where the rule is not violated. In my understanding, there are the three solutions compliant with MISRA 2.1: a) Assembler function: nop.h: Code: extern void nop(void); nop.asm: Code: NOP PROC foo.c Code: #include \"nop.h\" b) C-function encapsulation nop.h: Code: extern void nop(void); nop.c: Code: #include \"nop.h\" foo.c: Code: #include \"nop.h\" In this solution nop.c is not MISRA but the code is isolated. Foo.c is MISRA. c) macro-function nop.h: Code: #define nop()\ asm(\"nop\") foo.c: Code: #include \"nop.h\" The last solution could have an impact on OBJ file generation. Some (most of?) compiler requier to compile with a specific option when assembler code is use in C file. This last solution should compliant with MISRA 2.1 but not with MISRA 1.1 (inline assembler is not C standard). - misra-c - 23-08-2006 MISRA-C meeting 23-8-2006 The previous reply by lv is consistent with our views. |