[英]dereferencing pointer to incomplete type|
這是我的頭文件
#include<stdio.h>
#include<stddef.h>
char memory[25000]; //Declare an array of 25000 bytes in size
//Define data structure to save the details of the each memory block
struct metaData{
int status; //save the status of the block is free or whether it is already allocated
size_t bSize; //save the block size in bytes
struct metaData *next; //save the pointer to next header
};
struct header *firstBlock=(void*)memory; //Initialise a pointer to the starting address of the memory
void initializeMemory(){
firstBlock->bSize=25000-sizeof(struct metaData);
firstBlock->status=1;
firstBlock->next=NULL;
}
當我嘗試使用此InitializeMemory()時,它說將指針指向不完整的類型,並指向InitializeMemory()函數。 這是什么錯誤?
您已將firstBlock
聲明為struct header *
。 之所以收到“不完整類型”錯誤,是因為您實際上尚未定義一個稱為struct header
的結構-而是定義了struct metaData
。
請改用struct metaData *firstBlock
,它應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.