MISRA-C:2012 5.4 deviation procedure - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: General Questions (https://forum.misra.org.uk/forumdisplay.php?fid=27) +--- Thread: MISRA-C:2012 5.4 deviation procedure (/showthread.php?tid=1049) |
MISRA-C:2012 5.4 deviation procedure - ogawa.kiyoshi - 16-04-2014 For clarification, at 5.4 deviation procedure in MISRA-C:2012, There are codes, like this #define PORT (* (volatile unsigned char * )0x002) PORT = 0x010u; I try to compile and go like this. // file misrac-5-4.c #include "misra_c.h" // #include and type definitions. #define PORT (* (volatile unsigned char * )0x002) int main(void){ printf(" PORT = %x \n", (unsigned int) &PORT); PORT = 0x010u; return printf("End of File misrac-5-4.c: Deviation procedure\n"); } // file end command is cc -std=c99 -Wall misrac-5-4.c There are no error and no warning. The results are PORT = 2 Segmentation fault: 11 This in intended behavior? or Are there any good implementation? I use Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.1.0 Thread model: posix. By the way, I try to compile all examples of MISRA-C:2012. Are there any good place about sample codes without of the rules and directories. Re: MISRA-C:2012 5.4 deviation procedure - misra-c - 20-05-2014 The behaviour of your example will depend on whether the address created from the integer is 0x0002 is valid for your system. This is one of the reasons why rule 11.4 prohibits such conversions. A deviation record for this example against rule 11.4 would need to state that the address was valid. The examples from the MISRA C:2012 guidelines are available on the "MISRA C resources" section of the Bulletin Board, if you are logged in. This include all the examples in chapter 7 on directives and chapter 8 on rules. It does not include examples from the other chapters. |