65. namespace M {
class B { };
}
namespace N {
class Y : public M::B {
class X {
int a[i];
};
};
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
77. Brian W. Kernighan and
Dennis M. Ritchie(K&R)
利点
簡単に動くソフトウェア
main(){
printf(“Hello World!¥n”);
}
罠
2つとも可変引数関数()
初版1978
日本語版には「UNIX流プログラム書法と作法」
ANSI-C対応版1988
#include <stdio.h>
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
78. C言語と規約の歴史
1978 K&R The C programming Language(Bell Lab.)
1982 The C Puzzle Book(Bell Lab.)
1988 K&R ver.2(ANSI-C version: Bell Lab.
1989 C tarps and pit falls(Bell Lab.)
1989 ANSI-C:1989
1990 ISO/IEC 9899(same as ANSI-C)
1995 Safer C
1995 ISO/IEC 9899 Amd1
1998 MISRA C:1998
1999 ISO/IEC 9899
2004 MISRA C:2004
2011 ISO/IEC 9899
2012 MISRA C:2012
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
79. The C Puzzle BOOK
by Alan R. Feuer
利点
ソースコードと出力例・解説
がある。
Bit幅などにCの処理系による
違いがわかる。
初版1982, 改訂版1998
Bell Laboratory
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
80. C traps and pitfalls
by Andrew Koenig
利点
プログラマが遭遇する怪しいプログラム
例
MISRA Cで参照・引用
if (x = y) foo();
Newsletter :ACM SIGPLAN Notices:
http://www.literateprogramming.co
m/ ctraps.pdf The C Puzzle Bookが参
考文献。
1995
Bell Laboratory
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
81. Safer C developing
software for high-integrity
and safety- critical
systems.by Les Hatton規格の未定義、未規定、処理
系定義による動作の違いの
可能性を指摘
処理系による動作の違いを
避けるプログラミング
1995
http://www.leshatton.org
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
82. MISRA C-Training Kit内訳
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
The C Puzzle Book/C traps and pit falls
ISO/IEC 9899:2011(1999, 1995, 1990)
ESCR
ISO/IEC TS 17961
CERTC
MISRA C2012, 2004, 1998
110. ここまでのまとめ
The C puzzle BOOK, C Trap and pitfallsなどの困った
プログラムを排除する規約
国際規格ISO/IEC 9899の例をコンパイル
Undefined, Unspecified, Implementation defined
CERTCとTS17961は姉妹
Library, OSとの境界に着目
MISRA C
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
116. The spirit of C, Additional Principles for
C1X
ISO/IEC JTC1 SC22WG14 N125012. Trust the programmer, as a goal, is outdated in respect to the
security and safety programming communities. While it
should not be totally disregarded as a facet of the spirit of C, the
C1Xversion of the C Standard should take into account that
programmers need the ability to check their work.
13. Unlike for C9X, the consensus at the London meeting was that there
should be no invention, without exception. Only those features that
have a history and are in common use by a commercial
implementation should be considered. Also there must be care to
standardize these features in a way that would make the Standard
and the commercial implementation compatible.
14. Migration of an existing code base is an issue. The ability to mix and
match C89, C99, and C1X based code is a feature that should be
considered for each proposal.
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
117. 未定義(undefined)と未規定
(unspecified)
3.4.3 undefined behavior: behavior, upon use of a non portable
or erroneous program construct or of erroneous data, for which
this International Standard imposes no requirements
NOTE Possible undefined behavior ranges from ignoring the situation
completely with unpredictable results, to behaving during translation or
program execution in a documented manner characteristic of the
environment (with or without the issuance of a diagnostic message), to
terminating a translation or execution (with the issuance of a diagnostic
message).
EXAMPLE An example of undefined behavior is the behavior on integer
overflow.
3.4.4 unspecified behavior: use of an unspecified value, or
other behavior where this International Standard provides two
or more possibilities and imposes no further requirements on
which is chosen in any Instance
EXAMPLE An example of unspecified behavior is the order in which the2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
134. MISRA(Motor Industry Softwre Reliability
Association)
MIRA(欧州の自動車関連団体:Motor Industry Research
Association)
Development guideline for vehicle based software(ISO TR 15497:)
自動車用ソフトウェアの開発ガイドライン(自動車技術会TP-
01001)
Guidelines for the use of the C language in vehicle based
software(MISRA C:1998)
自動車用C言語利用のガイドライン(自動車技術会TP-01002)
C90対応
解説書はSESSAME WG3
MISRA C:2004(C90対応)
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
135. MISRA C
C言語規格のPortabilityに対する疑問から、SaferCというより
安全なC言語の書き方の提案があった
自動車業界の要請により自動車業界のコーディングルール
として1998年に発行。HIS(ドイツの自動車業界団体)が
Automotive SPICE(ISO/IEC 15504), ISO OSEK, ISO CANな
どとともに採用
日本からの意見を含めて第二版を2004年に発行
C99に対応した第三版を2012年に発行
(c)kaizen@wh.commufa.jp, @kaizen_nagoya組込み研修2018/06/05
136. 組込み開発者におくるMISRA C
組込みプログラミングの高信頼化ガイド
MISRA C 研究会(SESSAME WG3),
日本規格協会, 2004
C言語で書いたソフトウェアを他の
CPUに移植する際に問題となる事項
を洗い出し
C言語の規定のあいまいな事項を排
除して、不具合を減らす
参考文献
Safer C
C言語の落とし穴
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
155. Rule1.c
*****************************/
* File Name: rule1.c
* Author: kaizen @ wh.commufa.jp
* Date: 2004.09.14
* Version: 0.04
* Purpose: Test Use Only.
* Ruel section
Rule1:すべてのコードは ISO/IEC 9899:1990 を満
たしていなければならず, 拡張機能は許されない.
* [MISRAC開発ガイドライン テーブル3]
original Rule 1: All code shall conform to
ISO 9899 standard C,with no extensions
permitted.
**************************/
#define _rule1_c_
#include “../include/misrac.h”
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
/******************************
* output section
* Visual Studio 6.0 : no error, no warning
main START
far_ptr_arg = 4198400
pointer = 4198912
near_ptr_arg = 4198912
si32_var = -512
main END
* gcc 3.3.1 (cygwin) : no error, no warning
main START
far_ptr_arg = 4198581
pointer = 4198828
near_ptr_arg = 4198828
si32_var = -247
main END
* End: rule1.c (C) MISRA C Study Group Japan
* add result 2004.07.14
* add end-result and rule 2004.09.14
*****************************/
156. Rule.5
* rule 5: ISO C標準で使用している文字や拡張表記のみ使用
可能である.
* original rule 5: Only those characters and escape sequences
which are defined in the ISO C standard shall be used.
UI_8 ui8_var4 = '$'; /* NG: $は定義されていない文字 */
UI_8 ui8_var5 = '@'; /* NG: @は定義されていない文字*/
UI_8 ui8_var6 = ‘C’; /* NG: Cは定義されていない拡張表記 */
C標準で使用していない文字を認識。
OSで規定すべきこと->OSごとにStanding Deviationを規定するとよい。
2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
166. 2018/06/05 (c)kaizen@wh.commufa.jp, @kaizen_nagoya
主要参考文献
The Motor Industry Software Reliability Association(1994):Development
Guidelines for Vehicle Base Software,ISBN 0952415607
The Motor Industry Software Reliability Association(1998):Guidelines for
THE USE Of The language IN Vehicle Based Software ISBN 0952415690
Guidelines for the use of the C language in critical systems, 2013, ISBN
9781906400-11-8 PDF
JSAE(2002):JASO/TP-01001 自動車用ソフトウェアの開発ガイドライ
ン,社団法人自動車技術会
JSAE(2002):JASO/TP-01002 自動車用C言語利用のガイドライン、社
団法人自動車技術会
B.W.カーニハン,D.M.リッチー著,石田晴久(訳:1989)プログラミング言
語C、共立出版
A.コーニグ著.中村明(訳:2004)Cプログラミングの落とし穴,新紀元
社
アラン・R. フューアー 著, 田中 和明・手塚 忠則 (訳:2000) The C
PuzzleBook,カットシステム