假设我在下面有一个功能。
void function createBands(boolean option) {
int i, j;
int ***bands = (int ***)malloc((SIZE + 1) * sizeof(int **));
for (i = 0; i < SIZE; i++) {
bands[i] = (int **)malloc(HEIGHT * sizeof(int *));
for (j = 0; j < HEIGHT; j++)
bands[i][j] = (int *)malloc(WIDTH * sizeof(int));
}
iterator *it =
createIterator(params); // do not be confused it is a structure with
// methods andaeribute just like Iterator class in
// java . Methods are poniters to functions.
repare_array(bands[Size], it);
}
void prepare_array(int **band, iterator *it) { read_array(band, it); }
read_array(int **band, iterator *it) {
for (int i = 0; i < Height; i++)
band[i] = (int *)it->next();
}
// Now in Iterator.c I have the iterator structure with the methods etc I will
// write just some line form iterator.
void *next() {
byte *b =
a function that reads bytes form a file and returns byte * CORECTLY !!!;
return b == NULL ? NULL : bytetoT(b);
// this function make void form byte conversion but it doesnt work so I make
// only a cast in read_aray as you see. SUppose just return b wich is byte(i
// know in C isn't any byte but I redeclared all the types to be JAVA.)
}
问题是我应该在哪里分配波段,因为在这种情况下,函数返回的一维向量是可以的,因为我看到了函数范围内的值。但是当它返回数组 [i] 时,我得到了一个未分配的 3dVector。我需要使用数据形式 b 接收bands[size][i][j]。在 b 中,数据很好,然后我的频段为空。到目前为止,我所做的我在调用 read_array 之前在 prepare aray 中进行了另一次分配,在那里我分配了 **band,然后我得到了一些结果,但我不自信。对困惑感到抱歉!每一条评论都对我有好处。也许我所做的是好的,我不知道!我对 CI 并不陌生,只是长时间不使用指针。