0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

職業訓練
https://qiita.com/kaizen_nagoya/items/95368b63fa21d64271ec

Programmer, Day 11
https://qiita.com/kaizen_nagoya/items/f4ac0fd7e8ae419b7267

C言語(C++)が必要な人と必要ない人
https://qiita.com/kaizen_nagoya/items/2afe9e846b55b24cb6f1

C言語を習得する3つの方法
https://qiita.com/kaizen_nagoya/items/84cab0888c193bba429b

Programmer, Day 13
https://qiita.com/kaizen_nagoya/items/799b5198c2ede17f7d20

MCP入門 〜面倒なことはAIエージェントにやらせよう〜 を聞きながら
https://qiita.com/kaizen_nagoya/items/54b648c838fae8d57e38

職業訓練(IT) オープンソースとユーザビリティ教育。構造化とUMLを使って。
https://qiita.com/kaizen_nagoya/items/c41988c2f8ce1b61a08a

名古屋Reject会議 ふたたび
https://qiita.com/kaizen_nagoya/items/d35d2de4a35abb797126

Qiita Tech Festa 2025 自己記事一覧
https://qiita.com/kaizen_nagoya/items/83f7b7d9609d6789dc3a

<この項は書きかけです。順次追記します。>
This article is not completed. I will add some words and/or centences in order.
Este artículo no está completo. Agregaré algunas palabras en orden.

MISRA C

d1 misrac2012
https://qiita.com/kaizen_nagoya/items/20466d769a5c0dcc9d0e

d2 misrac2012
https://qiita.com/kaizen_nagoya/items/4d34b00565fbe877d30d

d3 misrac2012
https://qiita.com/kaizen_nagoya/items/668fea6a5693d8b4895d

d4 misrac2012
https://qiita.com/kaizen_nagoya/items/8778ce2afe8a705ff641

R1 misrac2012
https://qiita.com/kaizen_nagoya/items/768b7748890eedeb4922

R3 misrac2012
https://qiita.com/kaizen_nagoya/items/67113d4c64aa62745f5c

MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

Misra Example Suite at docker コンパイル完了までの道のり。docker(154) error(56)
https://qiita.com/kaizen_nagoya/items/71f04a0204d5a1114577

一つづつMISRAが作成した直したソースは別に解説します。
docker(201) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(1) D_04_03.c
https://qiita.com/kaizen_nagoya/items/780be9109348340e20e0

docker(202) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(2) R_02_02.c
https://qiita.com/kaizen_nagoya/items/496869b87dd3d29cea8b

docker(203) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(3) R_05_03.c
https://qiita.com/kaizen_nagoya/items/cb0d1da183f4f1e9e59d

docker(204) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(4) R_07_04.c
https://qiita.com/kaizen_nagoya/items/73b9f16638273a74d807

docker(205) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(5) R_08_04.c
https://qiita.com/kaizen_nagoya/items/c753db14cc95a9303fa5

docker(206) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(6) R_09_0x.c
https://qiita.com/kaizen_nagoya/items/8ad38c8728440688255c

docker(207) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(7) R_10_0x.c
https://qiita.com/kaizen_nagoya/items/05dd6f6c14aeafbe3e71

docker(208) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(8) R_11_0x.c
https://qiita.com/kaizen_nagoya/items/9962647a1b510825fa6e

docker(209) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(9) R_13_0x.c
https://qiita.com/kaizen_nagoya/items/dcd2de1267e3c3449536

docker(210) gcc(gnu), clang(llvm)コンパイルエラー・警告比較(10) R_14_0x.c
https://qiita.com/kaizen_nagoya/items/772f49486e7cca1dbeb9

gcc(gnu), clang(llvm)コンパイルエラー・警告比較(12) R_17_03.c, docker(165) error(50) https://qiita.com/kaizen_nagoya/items/f85e29050b99ea1c2538

Day 12

構造化

P154

関数ポインタテーブルを使う際、可読性を上げるにはコメントを書くことはもちろんだと思うが、それ以外に可読性を上げる方法はあるのか?

個々の関数名に意味があるものにする。

struct functbl daatatl[MAXSTATUS][MAXEVENT] = { { boil, BOILING},{economy, ECONOMY}, ..}

関数ポインタテーブルの要素である関数に意味がある。
Switch Caseで使う定数も意味があり、関数との関係がわかりやすくなっている。

順番に意味あるようにする。
1 優先度順にならべる。実行の順番が速くやってほしい順になっていれば、そのままCaseの順番にできる。
2 意味のあるかたまり同志を並べる。

Switch-case文は可読性は高いが抜け漏れのリスクが有るため、抜け漏れを無くす方法は流れ図を書くなどしたほうがいいということ。

状態遷移表が、ぬけもれなくす必須事項。

p158

main関数 ー> startup関数と読み替える。
hosted 環境でもmain関数は最上位とは限らない。一番最初。

C言語規格では、freestanding e3nvironmentでは、implementation definedでよいと書いていて、mainとは書いてない。
hosted environment(POSIX OSの上で動くC:Linux、Windowsなど)では、main 関数がstartupだと定義している。
機能は、最初から関数として書く。(C言語をはじめとするありとあらゆる関数言語)

https://www.open-std.org/jtc1/sc22/wg14/www/projects#9899
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf

4. Conformance

1 In this document, "shall" is to be interpreted as a requirement on an implementation or on a program; conversely, "shall not" is to be interpreted as a prohibition.
If a "shall" or "shall not" requirement that appears outside of a constraint or runtime-constraint is violated, the behavior is undefined. Undefined behavior is otherwise indicated in this document by the words "undefined behavior" or by the omission of any explicit definition of behavior. There is no difference in emphasis among these three; they all describe "behavior that is undefined".
A program that is correct in all other aspects, operating on correct data, containing unspecified behavior shall be a correct program and act in accordance with 5.2.2.4.
The implementation shall not successfully translate a preprocessing translation unit containing a #error preprocessing directive unless it is part of a group skipped by conditional inclusion.
A strictly conforming program shall use only those features of the language and library specified in this
document. It shall not produce output dependent on any unspecified, undefined, or implementationdefined behavior, and shall not exceed any minimum implementation limit.
EXAMPLE A strictly conforming program can use conditional features (see 6.10.10.4) provided the use is guarded by an appropriate conditional inclusion preprocessing directive using the related macro. For example:
#ifdef STDC_IEC_60559_BFP /* FE_UPWARD defined /
/
... /
fesetround(FE_UPWARD);
/
... /
#endif
The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause (Clause 7) is confined to the contents of the standard headers:





,





Additionally, a conforming freestanding implementation shall accept any strictly conforming program
where:
— the features specified in the header are used, except the following functions:
strcoll, strdup, strerror, strndup, strtok, strxfrm; and/or,
— the selected function memalignment from is used.
A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.1)
8 The strictly conforming programs that shall be accepted by a conforming freestanding implementation that defines STDC_IEC_60559_BFP or STDC_IEC_60559_DFP can also use features in
the contents of the standard headers , , and the strto
floating-point numeric
conversion functions (7.25.2) of the standard header , provided the program does not
set the state of the FENV_ACCESS pragma to "on".
All identifiers that are reserved when is included in a hosted implementation are
reserved when it is included in a freestanding implementation.
9 A conforming program is one that is acceptable to a conforming implementation.2)
10 An implementation shall be accompanied by a document that defines all implementation-defined
and locale-specific characteristics and all extensions.
Forward references: conditional inclusion (6.10.2), error directive (6.10.7), characteristics of floating
types (7.7), alternative spellings (7.9), sizes of integer types
(7.10), alignment (7.15), varying arguments (7.16), boolean type and
values (7.19), common definitions (7.22), integer types (7.23),
(7.27).

5.2.2 Execution environments

5.2.2.1 General
1 Two execution environments are defined: freestanding and hosted. In both cases, program startup
occurs when a designated C function is called by the execution environment. All objects with static
storage duration shall be initialized (set to their initial values) before program startup. The manner
and timing of such initialization are otherwise unspecified. Program termination returns control to
the execution environment.
Forward references: storage durations of objects (6.2.4), initialization (6.7.11).
5.2.2.2 Freestanding environment
1 In a freestanding environment (in which C program execution can take place without any benefit of an operating system), the name and type of the function called at program startup are
implementation-defined. Any library facilities available to a freestanding program, other than the
minimal set required by Clause 4, are implementation-defined.
2 The effect of program termination in a freestanding environment is implementation-defined.
5)An implementation can convert each instance of the same non-corresponding source character to a different member of
the execution character set.
§ 5.2.2.2
ISO/IEC 9899:202y (en) — N3550 working draft
5.2.2.3 Hosted environment
5.2.2.3.1 General
1 A hosted environment is not required to be provided, but shall conform to the following specifications if present.
5.2.2.3.2 Program startup
1 The function called at program startup is named main. The implementation declares no prototype
for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names can be used, as they
are local to the function in which they are declared):
int main(int argc, char argv[]) { / ... */ }
or equivalent;6) or in some other implementation-defined manner.
2 If they are declared, the parameters to the main function shall obey the following constraints:
— The value of argc shall be nonnegative.
— argv[argc] shall be a null pointer.
— If the value of argc is greater than zero, the array members argv[0] through argv[argc-1]
inclusive shall contain pointers to strings, which are given implementation-defined values
by the host environment prior to program startup. The intent is to supply to the program
information determined prior to program startup from elsewhere in the hosted environment.
If the host environment is not capable of supplying strings with letters in both uppercase and
lowercase, the implementation shall ensure that the strings are received in lowercase.
— If the value of argc is greater than zero, the string pointed to by argv[0] represents the
program name; argv[0][0] shall be the null character if the program name is not available
from the host environment. If the value of argc is greater than one, the strings pointed to by
argv[1] through argv[argc-1] represent the program parameters.
— The parameters argc and argv and the strings pointed to by the argv array shall be modifiable
by the program, and retain their last-stored values between program startup and program
termination.
5.2.2.3.3 Program execution
1 In a hosted environment, a program can use all the functions, macros, type definitions, and objects
described in the library clause (Clause 7).

定常状態 <-> 過渡状態
システムの初期化
 OSが起動するまえにシステムの初期化をする場合は、main関数を呼ぶ前にシステムの初期化が終わっている。ー>OSのありがたみ。
割り込み(タイマ=タイマ割り込みも含む)

図7.14は、まっとう。
割り込み
スタートアップルーチン(OS起動前、ハードウェアの初期化、OS起動を含む)
main関数 初期化の続きをするかどうかはシステムによる。

マイクロプロセッサの種類によっては、割り込みベクタを使用しないものがあります。

割り込みがないマイクロプロセッサがあるかも。

https://www.momoyama-usagi.com/entry/info-calc-sys21
https://tech-in-japan.github.io/articles/J162229/index.html

問 13 開発ドキュメントとしてソースコードのみしか存在しない場合、どのようにして構造図を創れば良いでしょうか。

開発文書としてソースコードが存在する場合、どのようにして構造図を創れば良いでしょうか。

ソースコードから構造図を自動生成すればよい。

問14 設計仕様書とソースコードが乖離する要因と、それを防ぐ方法を考えてくださし。

ソースコードとは別に設計書、仕様書を書くからダメ。
ソースコードから、設計仕様書を自動生成すれば、乖離しない。

問15 洗練化と手戻りの事例を挙げて、それぞれの要因とその後の影響を考えてください。

洗練化:自分の欲しいものを作っている場合には、毎日動くものを作り(daily build)自分で違和感、欲しいものと違うって感じるところを、次の1日で直してビルドする。ー>妥当性確認。
手戻り:自分が使うものでないものをつくるときは、本当になにが必要かわからず、市場分析が不十分であったり、利用者の意見の聞き取りが不十分で、大切なことが抜けていて、構造自体も作りなおした方がよさそうになった。

P162

Factoring 要素化
Refactoring 再要素化
構造の見直し
 関数単位にファイルにする。
 そのファイルの複雑度を計算する。
 目標値になったら、休憩。
 バグが出たら、バグの原因をつきとめるか、単純化してみる。
実行速度がライバルより遅ければ、速くするために単純化する。

広くみる、 状態遷移図
もれなくみる。 状態遷移表
時間
空間

本質と現象を区別する ー> 現象を描写することにより本質が見えてくる(現象論)

1モジュールの適切サイズ
 コメントなしで画面に収まる
 コメントなしで印刷すると1ページ

直交:物理現象だと11次元くらいがいいかも。

ソフトウェア品質

品質で大事なのは、安全、安心(security), 妥当性

安全、安心が大丈夫そうなら、妥当性が大事。

妥当性

自分のために作るソフトでは、毎日ビルドするのが大切(daily build)
毎日、これでいいかどうか、違和感がないか、もっとしたいことがあるかを考える。
ひとまず、これでいいと思えば、そこで止める。
なにか気になることがあれば、1日だけかけて改良する。
改良後も違和感がなければ止める。違和感があればまた1日作業する。

処理時間の高速化、プログラムを小さくするのに必要そうな道具を使っていると、自然と品質はよくなる。
品質を意識してよくしなくても、品質はあとからついてくるかも。

複雑度の測定

Ref.

program はじめてのC/C++ 構造化プログラミング
https://qiita.com/kaizen_nagoya/items/918148868c2afc1810d4

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?