C言語の変数には型があります。リテラルにも型があります。
数値リテラル
- 0U : unsigned
- 0L : long
- 0UL : unsigned long
- 0LL : long long
- 0ULL : unsigned long long
- 0.0F : float
サフィックス
文字リテラル
'\0'
: 文字列終端
※ ASCIIコード : NUL, null terminator, ナル文字, ヌル文字
NULL : 空ポインタ定数(ナル・ポインタ、ヌル・ポインタ)
C言語の変数には型があります。リテラルにも型があります。
サフィックス
'\0'
: 文字列終端※ 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つの一次元配列を用意して、途中で指している一次元配列を書き換えています。
データモデル | 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 を優先する。
static | 記憶域指定子なし | extern | |
C言語 | 内部結合定義 | 外部結合定義 | 仕様なし |
C++ | 内部結合定義 | 非const: 外部結合定義 const: 内部結合定義 |
外部結合定義 |