我试图用memset的一个结构元素,像这样:在结构元素上使用memset的正确方法是什么?
memset(&targs[i]->cs, 0, sizeof(xcpu));
但是,这样做让我分割故障。我不明白为什么这是失败的,也不知道如何让它工作。 在结构的元素上使用memset的正确方法是什么?为什么我的方法不起作用?
线,其分配用于targs存储器:
eargs **targs = (eargs **) malloc(p * sizeof(eargs *));
结构定义为结构体元件Cs(xcpu_context)和struct targs(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;
不要在C程序中从'malloc()'强制返回值。 – 2012-03-08 00:14:45
初始化* targs的代码在哪里? – 2012-03-08 00:17:20
@HansPassant - 它不在那里,可能是这个问题。 – 2012-03-08 00:19:20