7. 今頃 C 言語?
•
CPU が実行するのは機械語。
• C 言語は高級機械語:多くの CPU 提供者が、 CPU とアセン
ブラ、 C コンパイラを同時に出荷。
•
min-CAML では直接アセンブラを生成することによっ
て高速化を実現。
• C を生成すれば、対応 CPU が一気に広がる。
•
•
UNIX/Linux, TOPPERS などの OS は C で記述している
。
C コンパイラを C で記述している。
• C 言語をよくすると、 C コンパイラがよくなる。逆も真?
• アセンブラで書けることなら、 C で書ける。
12/14/13
(c)kaizen@wh.commufa.jp,
@kaizen_nagoya
7
8. 情報源
C 言語規格 ISO/IEC
9899
◦ WEB に審議文書を公開規格。
http://www.open-std.org/itc1/sc22/wg14/
MISRA-C(MIRA: Motor Industry
Research Association)
◦ 参考情報を下記
http://researchmap.jp/kaizen/MISRA-C/
12/14/13
(c)kaizen@wh.commufa.jp,
@kaizen_nagoya
8
10. C 言語規格のあらまし
の発展を阻害しない。
C 言語の仕様
OS の存在を前提とした ホスト環境( OS あ
り ,main 有)
OS の存在を必ずしも想定していない フリース
タンディング環境。 OS なくてもよく
Main は必要ない 。
C 言語規格には 「未規定」,「未定義」,
「処理系定義」 がある。
Rationale という根拠文書が別にある
C の精神 :the spirit of c
CPU
10
12/14/13
(c)kaizen@wh.commufa.jp,
@kaizen_nagoya
21. MISRA-C 履歴
C: 第一版 , 1998 C90 対応
MISRA C: 第二版 , 2004, C90 対応
MISRA Autocode, 2007/2009
MISRA C++ Guidelines for the use of the
C++ language in critical systems: 2008
MISRA C: 第三版 , 2012, C90/C99 対応
MISRA
23. MISRA Autocode
MISRA AC INT: Introduction to the MISRA guidelines for the use of
automatic code generation in automotive systems, 2007.
MISRA AC TL: Modelling style guidelines for the application of TargetLink
in the context of automatic code generation, November 2007.
MISRA AC AGC: Guidelines for the application of MISRA-C:2004 in the
context of automatic code generation,November 2007.
MISRA AC GMG: Generic modelling design and style guidelines, May
2009.
MISRA AC SLSF: Modelling design and style guidelines for the application
of Simulink and Stateflow, May 2009.
模擬試験の浮動小数点を自動生成で
固定小数点に変換
◦ 誤差・桁落ちを少なくするキャスト
◦ 0 割にならないように=>この規則ではできない=>他の検証、
証明が必要
28. 潜在型 (Underlying type:MISRA-C2004/C90 対
応)
1)
両演算対象の潜在型が等しい場合は , 演算対象の潜在
型
2) 両演算対象の潜在型が整数型で大きさが異なる場合は ,
大きい方の演算対象の潜在型
3) 両演算対象の潜在型が整数型で大きさが等しく符号属
性が異なる(一方が符号無し整数型で他方が符号付き整数
型)場合については,符号無しの演算対象の型
4) 一方の演算対象の潜在型が整数型で他方の演算対象の
潜在型が浮動小数点型の場合は,浮動小数点型の演算対象
の潜在型。例: 8 ビット符号無し整数型の変数 a と b
の間で加算を行った場合,式「 a+ b 」の潜在型は, 8
ビット符号無し整数 (式「 a + b 」の実際の型は,汎整数
拡張により int 型)
29. Essential Type-MISRA-C:2012
ISO/IEC
C1990, C1999 の両方に対応
Boolean character
singed
unsigned
enum<i>
floating
_Bool
char
signed char
unsigned char
named enum
float
singed short
unsigned short
double
singed int
unsigned int
long double
signed long
unsigned long
signed long long
unsigned long long
1. The use of expression of essentially floating type for these operands is constraint violation
2. An expression of essentially Boolean type should always be used where an operand is interpreted as a Boolean value.
3. An operand of essentially Boolean type should not be used where an operand is interpreted as a numeric value.
4. An operand of essentially character type should not be used where an operand is interpreted as a numeric value. The numeric values of character data are implementation defined.
5. An operand of essentially enum type should not be used in arithmetic operation because an enum object uses an implementation-defined integer type. An operation involving an enum object may therefore yield a result with an unexpected type. Note that an enumeration constant from an anonymous enum has essentially singed type.
5 Shift and bitwise operations should only be performed on operands of essentially unsigned type. The numeric value resulting from their use on essentially signed types is implementation defined.
6.