0
1

コミュニケーション関数

リンカ・ローダ実践開発テクニックの著者坂井弘亮は、KOZOSというオープンソースの小さなOSを公開している。
https://kozos.jp/kozos/

仕事をしながら、趣味でもプログラミングする感じ。
技術士(情報工学)の資格を取ったり、IPAで10歳前後の若者たちとセキュリティキャンプを実施したりしている。

C言語規格で定義しているコミュニケーション関数であるExitが出てくる。
人間であれ、プログラムであれ、コミュニケーションには、システムの違い、環境の違いに応じて対応する必要があることがわかる。
C言語のコミュニケーション関数の作りがわかれば、人間とのコミュニケーションにも類似の仕組みが必要かもしれないって気づくかも。

<この項は書きかけです。順次追記します。>
This article is not completed. I will add some words in order.

リンカ ローダ

N3220 Information technology — Programming languages — C N3220 working draft
https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3220.pdf
N3219 Information technology — Programming languages — C ISO/IEC 9899:2023 DIS Draft
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3219.pdf

C N3219 7.24.4 Communication with the environment
7.24.4.1 The abort function
7.24.4.2 The atexit function
7.24.4.3 The at_quick_exit function
7.24.4.4 The exit function
7.24.4.5 The _Exit function
7.24.4.6 The getenv function
7.24.4.7 The quick_exit function
7.24.4.8 The system function

リンカ・ローダ実践開発テクニック―実行ファイルを作成するために必須の技術-COMPUTER-TECHNOLOGY-坂井-弘亮
https://www.amazon.co.jp//dp/4789838072/
https://bookmeter.com/books/630946

参考文献にあるLinkers & Loadersは斜め読みしただけで、自分ではこういう道具は作らないだろうと勝手に思っていた。本書では簡易リンカの作成と、道具の作り方まで有るのがすごい。「setjmp()とlongjmp()」というコラムが1頁に入りきらず4頁になっているのに、節にしていないところも興味深い。
https://shop.cqpub.co.jp/hanbai/books/38/38071.html

checksym.c リンカ・ローダ実践開発テクニック(0) 坂井弘亮 coding(88)
https://qiita.com/kaizen_nagoya/items/51709d5989204ef2a371

ardump.c リンカ・ローダ実践開発テクニック 坂井弘亮(1) coding(89)
https://qiita.com/kaizen_nagoya/items/2a7bf3050ee6ac662272

binary.c リンカ・ローダ実践開発テクニック 坂井弘亮(2) coding(90)
https://qiita.com/kaizen_nagoya/items/23b985cefc5338677812

combine.c リンカ・ローダ実践開発テクニック 坂井弘亮(3) coding(91)
https://qiita.com/kaizen_nagoya/items/59161e3274270cfd2009

const.c, リンカ・ローダ実践開発テクニック 坂井弘亮(4) coding(92) error(123) docker(174)
https://qiita.com/kaizen_nagoya/items/6f74dbf637a91685d0d1

constructor.c リンカ・ローダ実践開発テクニック 坂井弘亮(5) coding(93)
https://qiita.com/kaizen_nagoya/items/37e14a0943907b6f836f

関数の調べ方

ソースコードから出発してもよい。
C言語規格から出発してもよい。
コンパイラから出発してもよい。

少なくとも、3つの道はひらけている。

上記の3つの道以外の「C言語教育」には近寄らない方がいいかもしれない。

ソースコード

何か一つのコンパイラでコンパイルしてみる。
コンパイラそのものを深掘りするよりも、
そのコンパイラで、このコードが通るようにすることに専念する。
コンパイルエラーが出たら記録する。

Error一覧(C/C++, python, bash...) Error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

コードがプログラマの意図通りの動作をするかどうかを確認する。
validationともいう。

C言語規格

C言語規格には、FreestandingというPosixOSを使わない仕様と、
HostedというPosixOSを使う仕様がある。

Hostedの場合には、関数がC言語の関数かPosixの関数かを調べるとよい。
https://pubs.opengroup.org/onlinepubs/9699919799/

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

コンパイラ

gccとClangと、Visual Studioの3つのコンパイラでコンパイルしてみるとよい。

3つのコンパイラでコンパイルできるコードは、Portabilityがあると言えるかもしれない。

gcc/g++(GNU) v.s. Clang/Clang++(LLVM) コンパイラ警告等比較、Error(13), C++(36)
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

OS

posix
https://pubs.opengroup.org/onlinepubs/9699919799/

関数調査

C言語と、POSIXで検索する。

binary.c

LinerLoaderTech
https://www.cqpub.co.jp/interface/download/2005/02/linker/LinkerLoaderTech.zip

binary.c
#include <stdio.h>
extern char __start_bindata;
extern char __stop_bindata;
int main()
{
  char * p;
  printf("__start_bindata = 0x%08x\n", (int)(&__start_bindata));
  printf("__stop_bindata  = 0x%08x\n", (int)(&__stop_bindata));
  for (p = &__start_bindata; p < &__stop_bindata; p++)
    putchar(*p);
  exit (0);
}

main

see
https://qiita.com/kaizen_nagoya/items/2a7bf3050ee6ac662272

printf

see
https://qiita.com/kaizen_nagoya/items/2a7bf3050ee6ac662272

putchar

C N3219 7.23.7 Character input/output functions
7.23.7.8 The putchar function

putchar.c
#include <stdio.h> 
int putchar(int c);

exit

C N3219 7.24.4 Communication with the environment
7.24.4.4 The exit function

Synopsis

exit.c
#include <stdlib.h>
[[noreturn]] void exit(int status);

Description

The exit function causes normal program termination to occur. No functions registered by the at_quick_exit function are called. If a program calls the exit function more than once, or calls the quick_exit function in addition to the exit function, the behavior is undefined.
First, all functions registered by the atexit function are called, in the reverse order of their registra- tion,349) except that a function is called after any previously registered functions that had already been called at the time it was registered. If, during the call to any such function, a call to the longjmp function is made that would terminate the call to the registered function, the behavior is undefined.
Next, all open streams with unwritten buffered data are flushed, all open streams are closed, and all files created by the tmpfile function are removed.
Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.

Returns

The exit function cannot return to its caller.

exit関数は、呼び出した関数に戻らないcallout.
main関数はintを返すとしている。

exit at posix

NAME

exit - terminate a process

SYNOPSIS
#include <stdlib.h>
void exit(int status);
DESCRIPTION

[CX] [Option Start] The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1-2017 defers to the ISO C standard. [Option End]
The value of status may be 0, EXIT_SUCCESS, EXIT_FAILURE, [CX] [Option Start] or any other value, though only the least significant 8 bits (that is, status & 0377) shall be available from wait() and waitpid(); the full value shall be available from waitid() and in the siginfo_t passed to a signal handler for SIGCHLD. [Option End]
The exit() function shall first call all functions registered by atexit(), in the reverse order of their registration, except that a function is called after any previously registered functions that had already been called at the time it was registered. Each function is called as many times as it was registered. If, during the call to any such function, a call to the longjmp() function is made that would terminate the call to the registered function, the behavior is undefined.
If a function registered by a call to atexit() fails to return, the remaining registered functions shall not be called and the rest of the exit() processing shall not be completed. If exit() is called more than once, the behavior is undefined.
The exit() function shall then flush all open streams with unwritten buffered data and close all open streams. Finally, the process shall be terminated [CX] [Option Start] with the same consequences as described in Consequences of Process Termination. [Option End]

RETURN VALUE

The exit() function does not return.

ERRORS

No errors are defined.

POSIXにmainがみあたらない。
整合性をどうとるとよいと理解するのか未確認。

コミュニケーション

502: Bad Gateway
リクエストの処理に時間がかかっています。しばらくしてから再度お試しください。
このページが繰り返し表示される場合は
support@qiita.comまでご連絡ください。
なお、Twitterにて最新の情報を配信しております。

ログインせずにアクセスすると表示する。理由は不明。

関連資料

私が効果を確認した「小川メソッド」
https://qiita.com/kazuo_reve/items/a3ea1d9171deeccc04da

' @kazuo_reve 新人の方によく展開している有益な情報
https://qiita.com/kazuo_reve/items/d1a3f0ee48e24bba38f1

' @kazuo_reve Vモデルについて勘違いしていたと思ったこと
https://qiita.com/kazuo_reve/items/46fddb094563bd9b2e1e

自己記事一覧

Qiitaの記事に3段階または5段階で到達するための方法
https://qiita.com/kaizen_nagoya/items/6e9298296852325adc5e

物理記事 上位100
https://qiita.com/kaizen_nagoya/items/66e90fe31fbe3facc6ff

量子(0) 計算機, 量子力学
https://qiita.com/kaizen_nagoya/items/1cd954cb0eed92879fd4

数学関連記事100
https://qiita.com/kaizen_nagoya/items/d8dadb49a6397e854c6d

統計(0)一覧
https://qiita.com/kaizen_nagoya/items/80d3b221807e53e88aba

品質一覧
https://qiita.com/kaizen_nagoya/items/2b99b8e9db6d94b2e971

言語・文学記事 100
https://qiita.com/kaizen_nagoya/items/42d58d5ef7fb53c407d6

医工連携関連記事一覧
https://qiita.com/kaizen_nagoya/items/6ab51c12ba51bc260a82

自動車 記事 100
https://qiita.com/kaizen_nagoya/items/f7f0b9ab36569ad409c5

通信記事100
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7

日本語(0)一欄
https://qiita.com/kaizen_nagoya/items/7498dcfa3a9ba7fd1e68

英語(0) 一覧
https://qiita.com/kaizen_nagoya/items/680e3f5cbf9430486c7d

転職(0)一覧
https://qiita.com/kaizen_nagoya/items/f77520d378d33451d6fe

仮説(0)一覧(目標100現在40)
https://qiita.com/kaizen_nagoya/items/f000506fe1837b3590df

音楽 一覧(0)
https://qiita.com/kaizen_nagoya/items/b6e5f42bbfe3bbe40f5d

@kazuo_reve 新人の方によく展開している有益な情報」確認一覧
https://qiita.com/kaizen_nagoya/items/b9380888d1e5a042646b

Qiita(0)Qiita関連記事一覧(自分)
https://qiita.com/kaizen_nagoya/items/58db5fbf036b28e9dfa6

鉄道(0)鉄道のシステム考察はてっちゃんがてつだってくれる
https://qiita.com/kaizen_nagoya/items/26bda595f341a27901a0

安全(0)安全工学シンポジウムに向けて: 21
https://qiita.com/kaizen_nagoya/items/c5d78f3def8195cb2409

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

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一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

++ Support(0) 
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514

Coding(0) Rules, C, Secure, MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0

プログラマによる、プログラマのための、統計(0)と確率のプログラミングとその後
https://qiita.com/kaizen_nagoya/items/6e9897eb641268766909

なぜ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

Python(0)記事をまとめたい。
https://qiita.com/kaizen_nagoya/items/088c57d70ab6904ebb53

官公庁・学校・公的団体(NPOを含む)システムの課題、官(0)
https://qiita.com/kaizen_nagoya/items/04ee6eaf7ec13d3af4c3

「はじめての」シリーズ  ベクタージャパン 
https://qiita.com/kaizen_nagoya/items/2e41634f6e21a3cf74eb

AUTOSAR(0)Qiita記事一覧, OSEK(75)
https://qiita.com/kaizen_nagoya/items/89c07961b59a8754c869

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

LaTeX(0) 一覧 
https://qiita.com/kaizen_nagoya/items/e3f7dafacab58c499792

自動制御、制御工学一覧(0)
https://qiita.com/kaizen_nagoya/items/7767a4e19a6ae1479e6b

Rust(0) 一覧 
https://qiita.com/kaizen_nagoya/items/5e8bb080ba6ca0281927

100以上いいねをいただいた記事16選
https://qiita.com/kaizen_nagoya/items/f8d958d9084ffbd15d2a

小川清最終講義、最終講義(再)計画, Ethernet(100) 英語(100) 安全(100)
https://qiita.com/kaizen_nagoya/items/e2df642e3951e35e6a53

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on my individual experience. It has nothing to do with the organization or business to which I currently belong.

文書履歴(document history)

ver. 0.01 初稿  20240706

最後までおよみいただきありがとう4ざいました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

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