我已经定义了 struct Node 和 createNode 函数。
typedef struct {
int r, c;
int val;
struct Node* down, *right;
} Node;
typedef Node* NodePointer;
NodePointer createNode(int r,int c,int val) {
NodePointer p = (NodePointer)malloc(sizeof(NodePointer));
if (p != NULL) {
p->r = r;
p->c = c;
p->val = val;
p->down = p->right = NULL;
}
return p;
}
然后当我尝试在主函数中使用它时
int i = 0;
NodePointer* rows = (NodePointer*)malloc(50*sizeof(NodePointer));
for (i = 0; i < 20; i++) {
rows[i] = createNode(i,i+10,i*i);
}
它抛出运行时错误,但是当我像这样更改 for 循环时(更改在 for 循环中 - 只执行一次):
for (i = 0; i < 1; i++) {
rows[i] = createNode(i,i+10,i*i);
}
它没有抛出错误。所以我问我做错了什么;错误:
Zad1: malloc.c:2374: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.
我是一名优秀的程序员,十分优秀!