MISRA-C:2012 5.4 deviation procedure

Questions and discussions about MISRA C not fitting under migration or rules forums

Moderators: misra-c, david ward

Post Reply
ogawa.kiyoshi
Posts: 15
Joined: Fri May 27, 2005 10:08 am
Company: NMIRI, Gifu-University, TOPPERS project
Location: Japan

MISRA-C:2012 5.4 deviation procedure

Post by ogawa.kiyoshi » Wed Apr 16, 2014 3:17 am

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 <stdio.h> 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.
Dr. OGAWA Kioshi
@kaizen_nagoya

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: MISRA-C:2012 5.4 deviation procedure

Post by misra-c » Tue May 20, 2014 12:38 pm

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

Post Reply

Return to “General Questions”