構造体は何が何でも使いたくないらしい
#include <stdio.h> #define NULL_PTR ( (void*)0 ) #define ROMSIZE ( 16 ) typedef unsigned char byte; const byte external_rom[ROMSIZE] = { 0x00u, 0x01u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x07u, 0x08u, 0x09u, 0x0Au, 0x0Bu, 0x0Cu, 0x0Du, 0x0Eu, 0x0Fu, }; static byte itemA[1]; static byte itemB[2]; static byte itemC[3]; static byte * const mirror[ROMSIZE] = { &itemA[0], NULL_PTR, NULL_PTR, NULL_PTR, &itemB[0], &itemB[1], NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR, &itemC[0], &itemC[1], &itemC[2], NULL_PTR, }; static void copy_innerram(const byte external[16]); int main(void) { copy_innerram(external_rom); printf("itemA: %d\n", itemA[0]); printf("itemB: %d, %d\n", itemB[0], itemB[1]); printf("itemC: %d, %d, %d\n", itemC[0], itemC[1], itemC[2]); return 0; } static void copy_innerram(const byte external[16]) { int idx = 0; for (idx = 0; idx < ROMSIZE; idx++) { if (mirror[idx] != NULL_PTR) { *mirror[idx] = external_rom[idx]; } } }
使い方ヒント: 「これは臭う」という行を見付けたら、各行のをクリックしてマーキングしておきましょう(要Twitter OAuth認証)
しみじみこないぜ
コメント投稿には、twitter認証が必要です。
Twitter認証
mirrorで指していない領域を読み取ると割込みが発生するとか。