Translation Unit.
標準的な翻訳単位
- 1つのソースファイル (
*.c) - 上記のソースファイルからインクルードされた全てのヘッダファイル (
*.h)- ヘッダファイルの中からインクルードされたヘッダファイルも全て含む。
Translation Unit.
*.c)*.h)
整数拡張 (integer promotions)、汎整数拡張、汎整数昇格
C言語の変数には型があります。同様にリテラルにも型があります。
※ ASCIIコード : NUL, null terminator, ナル文字, ヌル文字
NULL : 空ポインタ定数(ナル・ポインタ、ヌル・ポインタ)
-I や /I オプション、環境変数で指定されたディレクトリC言語の標準ライブラリ関数 setjmp() と longjmp() を呼び出すことで多段の関数呼出階層を飛び越えるジャンプ(いわゆるGOTO処理)を実現できます。しかしながら、現代的なプログラミングでは GOTO文 が忌避されるように、setjmp() と longjmp() を使ったジャンプは推奨されません。やむを得ず setjmp() と longjmp() で実装された既存のソースコードを理解するための助けとなることを目論んだ解説です。
C言語の多次元配列へのポインタの説明とサンプルコードです。
最初は導入です。C言語の入門書にも登場する配列とポインタの関係を説明します。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <stdio.h> #define NUMBER_OF_COLUMNS 4 int main(void) { int linear_array_x[NUMBER_OF_COLUMNS] = { 1, 2, 3, 4}; int linear_array_y[NUMBER_OF_COLUMNS] = { 11, 12, 13, 14}; int *top_of_columns; top_of_columns = linear_array_x; printf("top_of_columns[1] = %d\n", top_of_columns[1]); /* 2 */ printf("top_of_columns[3] = %d\n", top_of_columns[3]); /* 4 */ top_of_columns = linear_array_y; printf("top_of_columns[1] = %d\n", top_of_columns[1]); /* 12 */ printf("top_of_columns[3] = %d\n", top_of_columns[3]); /* 14 */ return 0; } |
もっともシンプルな例です。整数型の1次元配列を定義して、配列の先頭要素へのアドレスをポインタ変数 int *top_of_columns に代入しています。「ポインタ top_of_columns は一次元配列の先頭要素を指している」ということを明確にするために、2つの一次元配列 linear_array_x[] と linear_array_y[] を用意して、途中で top_of_columns が指している一次元配列を linear_array_x[] から linear_array_y[] に書き換えています。
| データモデル | short | int | long | long long | void* | 適用 |
|---|---|---|---|---|---|---|
| 16 | 16 | 32 | N/A | 16 | 一般的な16bit環境 (x86) | |
| ILP32 | 16 | 32 | 32 | 64 | 32 | 一般的な32bit環境 |
| LLP64 | 16 | 32 | 32 | 64 | 64 | 64bit Microsoft Windows |
| LP64 | 16 | 32 | 64 | 64 | 64 | 64bit Linux, macOS, iOS |
enum型はsizeof(int)を超えることはない。
Microsoft Visual Studio において enum型 は int で固定である。
一方, 処理系(IAR Embedded Workbench, CodeWarrierなど)によってはenum定数で保持に必要な最小の型を使用する。範囲指定がなければ unsigned よりも signed を優先する。