Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA-C:2012 5.4 deviation procedure
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.
<t>Dr. OGAWA Kioshi<br/>
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.
Posted by and on behalf of the MISRA C Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)