次のように、構造体要素で memset を使用しようとしています。
memset( &targs[i]->cs, 0, sizeof( xcpu ) );
ただし、そうするとセグメンテーション違反が発生します。なぜこれが失敗するのか、どうすればうまくいくのかわかりません。構造体の要素で memset を使用する適切な方法は何ですか? また、私の方法が機能しないのはなぜですか?
ターゲットにメモリを割り当てる行:
eargs **targs = (eargs **) malloc(p * sizeof(eargs *));
構造体要素 cs (xcpu_context) および構造体タグ (execute_args) の構造体定義:
typedef struct xcpu_context {
unsigned char *memory;
unsigned short regs[X_MAX_REGS];
unsigned short pc;
unsigned short state;
unsigned short itr;
unsigned short id;
unsigned short num;
} xcpu;
typedef struct execute_args {
int ticks;
int quantum;
xcpu cs;
} eargs;