How to compile MISRA-C:2012 Example Suite
どうやって MISRA Example Suiteをコンパイルするか
https://researchmap.jp/joydcij21-1861956/
Dr. Kiyoshi Ogawa
This is a part of proposing paper for WOCS2015 and Safety Engineering Symposium Japan 2015 by Science Counsil of Japan.
これはWOCS2015と安全工学シンポジウム2015への提出論文の一部です。
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の文書をご確認ください。
https://www.misra.org.uk/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
- 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.
2 MISRA-C
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.
- Header file, *.h
- C function program of a Rule or Directives, like R_nn_mm.c or D_nn_mm.c respectively.
- 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.
3.1.1.1 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 };
3.1.1.2 mc3_header.h
There are 2 type of declaration, common functions and individual functions.
3.1.1.2.1 common functions
common functions has 4 type.
//3.1.1.2.1.1 get value
extern bool get_bool ( void );
extern char_t get_char ( void );
//...
//3.1.1.2.1.2 get pointer(ptr)
extern bool *get_bool_ptr ( void );
extern char_t *get_char_ptr ( void );
//...
//3.1.1.2.1.3 use value
extern void use_bool ( bool use_bool_param );
extern void use_char ( char_t use_char_param );
//...
//3.1.1.2.1.4 use pointer(ptr)
extern void use_void_ptr ( void * void_ptr_param );
extern void use_bool_ptr ( bool *use_bool_ptr_param );
//...
//3.1.1.2.2 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
3.1.2.1, 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 -
D__error_debug__.
If you want to see compile error, you can compile with -
D__error_debug__
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)printf("%d",use_bool_param);
}
void use_char ( char_t use_char_param ){
(void)printf("%d",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){
printf("%d\n",(int)xyz);
}
#endif
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
ps
If your compiler is different behavior, please inform me through the MISRA Forum.
Reference
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をコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00
MISRA C.2.1 Type widening in integer promotion,(wicm3.c )
https://qiita.com/kaizen_nagoya/items/6a24db5d51efae358cfb
MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb
MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74
cpprefjp - C++日本語リファレンス
コンパイラの実装状況
typedef は C++11 ではオワコン
C99からC++14を駆け抜けるC++講座
コピペコンパイルエラーあるある
C++ Error Message Collection(1)does not name a type, 11 articles
dockerにclang
docker gnu(gcc/g++) and llvm(clang/clang++)
コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
Compare the contents of C++N4910:2022, C++N4741:2018 and C++N4606:2015
C++ sample list
clang++, g++コンパイルエラー方針の違いの例
astyle 使ってみた
C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること
https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1
コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da
Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f
C++2003とC++2017でコンパイルエラーになるならない事例集
https://qiita.com/kaizen_nagoya/items/a13ea3823441c430edff
Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d
cpprefjpのdecltypeをコンパイル試験
https://qiita.com/kaizen_nagoya/items/090909af702f0d5d8a67
MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74
C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp
https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed
ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1
C言語(C++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a
C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9
'wchar.h' file not found で困った clang++ macOS
https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11
Open POSIX Test Suiteの使い方を調べはじめました
https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc
MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
Document History
ver. 1.00 English only, 20180322
ver. 1.01 Add some Japanese, 20180323
ver. 1.02 Rearrange numbers, 20180325
ver. 1.03 add References
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.