大家来帮我看看这个程序错在哪里?
#define BLKSIZ 80#define STKSIZ 1000
typedef union{
char *link;
char data[BLKSIZ];
}BLOCK;
static BLOCK *btm_of_heap;
static BLOCK *top_of_heap;
static BLOCK *heap;
void Init_Heap(){
BLOCK *ptr;
int blk;
heap=(BLOCK *)malloc(BLKSIZ);
btm_of_heap=heap;
ptr=heap;
for(blk=0; blk<49; blk++){
ptr->link=(BLOCK *)malloc(BLKSIZ);
ptr=ptr->link;
}
ptr->link=NULL;
top_of_heap=ptr;
}
void My_Free(BLOCK *ptr){
if(ptr>=btm_of_heap){
if(ptr<top_of_heap){ /*Block is from my heap*/
ptr->link=heap;
heap=ptr;
return;
} else if(free(ptr)){ /*Block is from C-Ware's heap*/
return;
}
}
puts("\nAttempt to free unallocated block!\n\7");
exit(1);
}
BLOCK *Allocate(int bytes){
BLOCK *ptr;
if(bytes<=BLKSIZ){ /* 要求的内存块大小小于链表维护的内存块大小 */
if(heap!=0){ /* 有空闲块 */
ptr=heap;
heap=heap->link;
return ptr;
}
}
if(ptr=(BLOCK *)malloc(bytes)){ /* 要求的内存块大小大于链表维护的内存块大小或者没有空闲块 */
return ptr;
}
puts("Insufficient memory:malloc()\n\7");
exit(1);
}
void main()
{
BLOCK *main_ptr
Init_Heap();
main_ptr=Allocate(80);
My_Free(main_ptr);
}