1
我有一個名爲S的結構體和一個指向結構體S的名爲A的指針數組。我的函數T將一個指向結構體S的指針作爲參數。向前聲明一個指向結構的指針數組?
struct S *A; //forward declare array A of (pointers to) structs
...
void T(struct S *s){//function that accepts pointer to struct S
...
}
void otherFunction(){
...
T(A[i-1]); //Yields error Incompatible type for argument 1
}
int main(){
A = malloc(100 * sizeof(struct S*)); //initialize array
int i;
for(i = 0; i < NumBowls; i++){
A[i] = malloc(100 * sizeof(struct S));//initialize structs in array
}
otherFunction();
}
隨着打印語句,我能看到A [I-1]是一個類型的struct的,但是沒有指針至S這正是我想要的。這可能是因爲我轉發宣告A嗎?