【发布时间】:2018-07-29 11:59:41
【问题描述】:
所以当我 malloc 一个数组是 struct 的成员时,我很难弄清楚发生了什么?
出现以下error 消息:
“赋值使指针变成整数而不进行强制转换”。
如果有人能帮我看看我在malloc 中哪里出错了,我们将不胜感激。
typedef struct _big_num {
int nbytes; // size of array
Byte *bytes; /// array of Bytes
} BigNum;
void initBigNum(BigNum *n, int Nbytes)
{
int i;
n->nbytes = Nbytes;
for (i = 0; i < Nbytes; i++) {
n->bytes[i] = malloc(sizeof(Byte)); //This is where the error came up
n->bytes[i] = 0;
assert(n->bytes[i] == 0);
}
return;
}
【问题讨论】:
-
n->bytes[i]是什么?您确定此索引存在(您有权访问它)吗?