this is my header file
#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;
}
and when I try to use this InitializeMemory() it says dereferencing pointer to incomplete type and pointed to InitializeMemory() funtion. What is the error of this?
You've declared firstBlock
as a struct header *
. You're receiving the "incomplete type" error because you haven't actually defined a structure called struct header
- you've defined struct metaData
instead.
Use struct metaData *firstBlock
instead and it should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.