取消引用指向不完整类型的指针

时间:2016-11-24 20:56:28

标签: c methods struct

这是我的头文件

   #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()函数。这有什么错误?

1 个答案:

答案 0 :(得分:1)

您已将firstBlock声明为struct header *。您收到“不完整类型”错误,因为您实际上没有定义名为struct header的结构 - 您已经定义了struct metaData

使用struct metaData *firstBlock代替它,它应该有效。