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++日本語リファレンス
https://cpprefjp.github.io/
コンパイラの実装状況
https://cpprefjp.github.io/implementation-status.html
typedef は C++11 ではオワコン
https://qiita.com/Linda_pp/items/44a67c64c14cba00eef1
C99からC++14を駆け抜けるC++講座
https://qiita.com/yumetodo/items/e49a673afd9a3ecb81a8
コピペコンパイルエラーあるある
https://qiita.com/kaizen_nagoya/items/29c832de9d762aed2761
C++ Error Message Collection(1)does not name a type, 11 articles
https://qiita.com/kaizen_nagoya/items/acb9f1a9b5aad6df06bd
dockerにclang
https://qiita.com/kaizen_nagoya/items/8829ffeee397eda50e80
docker gnu(gcc/g++) and llvm(clang/clang++)
https://qiita.com/drafts/059874ea39c4de64c0f7
コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da
Compare the contents of C++N4910:2022, C++N4741:2018 and C++N4606:2015
https://qiita.com/kaizen_nagoya/items/483246d40f98abff7ded
C++ sample list
https://qiita.com/kaizen_nagoya/items/54ad75b73825b7c04f86
clang++, g++コンパイルエラー方針の違いの例
https://qiita.com/kaizen_nagoya/items/ea6e5009fe126d270a82
astyle 使ってみた
https://qiita.com/kaizen_nagoya/items/3c9a87a781d53a1a23f3
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
C++ Support(0)
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514
Coding Rules(0) C Secure , MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0
Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794
Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0
線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001
OSEK OS設計の基礎 OSEK(100)
https://qiita.com/kaizen_nagoya/items/7528a22a14242d2d58a3
Error一覧(C/C++, python, bash...) Error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8
なぜdockerで機械学習するか 書籍・ソース一覧作成中 (目標100)
https://qiita.com/kaizen_nagoya/items/ddd12477544bf5ba85e2
言語処理100本ノックをdockerで。python覚えるのに最適。:10+12
https://qiita.com/kaizen_nagoya/items/7e7eb7c543e0c18438c4
プログラムちょい替え(0)一覧:4件
https://qiita.com/kaizen_nagoya/items/296d87ef4bfd516bc394
TOPPERSまとめ #名古屋のIoTは名古屋のOSで
https://qiita.com/kaizen_nagoya/items/9026c049cb0309b9d451
docker(0) 資料集
https://qiita.com/kaizen_nagoya/items/45699eefd62677f69c1d
Qiita-dockerお宝鑑定団
https://qiita.com/kaizen_nagoya/items/509e125263559b5aed5b
The C++ Standard Library: clang++とg++でコンパイルしてみた(まとめ):14件
https://qiita.com/kaizen_nagoya/items/9bdfaa392443d13e5759
C++17 - The Complete Guide clang++とg++でコンパイルしてみた(まとめ):4件
https://qiita.com/kaizen_nagoya/items/c000f307e642990781e1
C++N3242, 2011, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91
Autosar Guidelines C++14 example code compile list(1-169)
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76
プログラマによる、プログラマのための、統計と確率のプログラミングとその後 統計と確率一覧(0)
https://qiita.com/kaizen_nagoya/items/6e9897eb641268766909
一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39
<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.
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.