Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What are the problem?

どうやって MISRA Example Suiteをコンパイルするか

How to compile MISRA-C:2012 Example Suite

どうやって MISRA Example Suiteをコンパイルするか
Dr. Kiyoshi Ogawa

This is a part of proposing paper for WOCS2015 and Safety Engineering Symposium Japan 2015 by Science Counsil of Japan.

This description has no official relation with MIRA, MISRA and MISRA-C.
This is only an user, a programmer effort for MISRA-C.
この記述はMIRA, MISRA, MISRA Cの公式な関係はありません。
プログラマのMISRA Cへの努力です。

If you want to compile MISRA-C Example Suite on the MISRA Forum, please read this document.
MISRA FORUMの文書をご確認ください。

Some codes may be compile error or only warning are depend on each C compiler implementation.
Some compile errors may be intentions of display wrong codes.

Now, I use LLVM(clang) 3.5- Xcode 6.0.
Xcode6.0 LLVM3.5利用。

Before you compile the codes, please read some back ground information, which are very important to avoid errors.


1 C programming language

  1. C言語。 C programming language is using C compiler and operating system(OS) and its standard is ISO/IEC 9899, working draft(WG14 N1570) http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf can read through ISO/IEC JTC1 SC22 WG14 web.


MISRA-C is a cording standard on C programming language for Automotive Industry and Safety Industry. MISRA Forum is a resource of the guide and example program.

3 Example program from MISRA Forum

There are some example program the name is MISRA C:2012 Examples Suite in the MISRA Forum.
Some program are in the guide, MISRA-C:2012 Guidelines for the Use of the C Language in Critical Systems, on MISRA web shop.

There are more than 150 programs.
3 types of C langue files in the Example Suite.
1) Header file, *.h
2) C function program of a Rule or Directives, like R_nn_mm.c or D_nn_mm.c respectively.
3) C function program of calling a functions(above) on a Rule section or a Directives section, such as R_nn_support.c, D_nn_support.c, R__nn_system.c or D_nn_system.c.
X_nn_system for host environment and X_nn_support for free standing environment.

3.1 Header files

3.1.1 common header file

There are 2 common header file, mc3_header.h and mc3_types.h. "mc3" mean misra-c version 3, 2012. mc3_types.h

typedef          char           char_t;
typedef          float          float32_t;
//for C99
#include <stdint.h>
#include <stdbool.h>
typedef _Bool bool_t;
//for C90
typedef signed   char           int8_t;
typedef signed   short          int16_t;
typedef signed   int            int32_t;
typedef unsigned char           uint8_t;
typedef unsigned short          uint16_t;
typedef unsigned int            uint32_t;
typedef          int            bool_t;
typedef          int            bool;
enum { false, true }; mc3_header.h

There are 2 type of declaration, common functions and individual functions. common functions

common functions has 4 type.

// get value 
extern bool get_bool ( void );
extern char_t get_char ( void );
// get pointer(ptr)
extern bool *get_bool_ptr ( void );
extern char_t *get_char_ptr ( void );
// use value
extern void use_bool ( bool use_bool_param );
extern void use_char ( char_t use_char_param );
// use pointer(ptr)
extern void use_void_ptr ( void * void_ptr_param );
extern void use_bool_ptr ( bool *use_bool_ptr_param );
// individual functions
extern void R_8_1 ( void );
extern void R_8_2 ( void );

3.1.2 Individual header file

Some C program file has own header file, for example Directives, in D_04_01.c

#include "D_04_01.h"

4 Add some codes for compile

4.1 #define some compile switch

4.1.1 #ifdef error_debug

There are some error codes.
I add error_debug .
If you will not see compile error, then compile without -


If you want to see compile error, you can compile with -


If an individual file has no code, then before a calling functions in X_nn_sytem.c and X_nn_support.c, please add #ifdef error_debug.

4.1.2 #ifdef debug

If a program have no output, then add #ifdef debug and printf() output the console.

4.2 Add some definitions of functions and variables.

4.2.1 common functions

I made a file use_data.c like this.(please remove .txt from file name. it is constraints of this site.)

void use_bool ( bool use_bool_param ){
void use_char ( char_t use_char_param ){

4.2.2 individual functions and variables

I made a file use_func.c like this.(please remove .txt from file name. it is constraints of this site.)

// R_05_03.c
#ifdef __R_05_03__ 
void   g (  struct astruct* xyz){

In this file, my intention is output the state.

4.2.3 Makefile(please remove .txt from file name. it is constraints of this site.)

Now I am making Makefile for compile activities.

These 3 files are beta version to maintain daily compile.
Official release will be at one of symposium 2015 above.

The compile command may be

$ make dir4
$ make rule02
$ make rule22

dir1, dir2, dir3 and rule01 have no effective code.

The results will be reported next month at MISRA Forum.

Best Regards
Dr Kiyoshi Ogawa

If your compiler is different behavior, please inform me through the MISRA Forum.


Safer C:

Developing Software for High-Integrity and Safety-Critical Systems (The Mcgraw-Hill International Series in Software Engineering), Les Hatton, Mcgraw-Hill (Tx)(1995)

C Traps and Pitfalls

Andrew Koenig, Addison-Wesley Professional(1989/01/01)

C Puzzle Book, The

Alan R. Feuer, Addison-Wesley Professional(1998/10/15)


どうやって MISRA Example Suiteをコンパイルするか

MISRA C.2.1 Type widening in integer promotion,(wicm3.c )

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認

MISRA C まとめ #include

MISRA C++ 5-0-16


Document History

ver 1.00 English only, 20180322
ver 1.01 Add some Japanese, 20180323
ver 1.02 Rearrange numbers, 20180325

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What are the problem?