メモリブロック
- どこ?=場所=先頭アドレス
- どのくらい?=サイズ
- なに?=中身
メモリセルとは区別する。メモリセクション/セグメントともちょっと別。
xがメモリブロックを指すなら、
- どこ → &x
- どのくらい → sizeof(x)
- なに → 例えば次の関数
#includevoid dumpmem(unsigned char *p, unsigned size)
{
static int hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};unsigned char *bound;
int u;
for (bound = p + size; p < bound; p++) {
u = *p;
putchar(hex[(u&0xF0)>>4]); // 上位ニブル
putchar(hex[u&0x0F]); // 下位ニブル
putchar(';'); // 1バイトの終わりを示す
};
}// お試し
main()
{
int foo[] = {1, 0x230F, 0x450F0, 0x670F00, 0x890F000};
dumpmem((unsigned char*)foo, 5*4);
}
- 変数の宣言は(省略可能ではあるが)だが必須、なぜか?
- 関数の宣言はイイカゲンでどうでもよかった、なぜか?