主题:动态存储管理中的问题
#include"stdio.h"
#include"malloc.h"
#define footloc(p) (p)+(p)->size-1
#define max 1000
#define e 10
typedef struct word
{
union
{
struct word *llink;
struct word *uplink;
}a;
int tag;
int size;
struct word *rlink;
}word,head,foot,*space;
main()
{
space p,pav,f;
int n;
p=(word *)malloc(sizeof(word));
printf("%d\n",p);
getch();
pav=p+1;
pav->rlink=pav->a.llink=pav;
printf("%d\n",sizeof(word));
getch();
printf("%d\n",pav->rlink);
getch();
printf("%d\n",pav->a.llink);
getch();
pav->tag=0;
pav->size=max;
p=footloc(pav);
printf("%d\n",p);
getch();
p->a.uplink=pav;
printf("%d\n",p->a.uplink);
getch();
p->tag=0;
printf("%d\n",p+1);
getch();
(p+1)->tag=1;
n=300;
for(p=pav;p&&p->size<n&&p->rlink!=pav;p=p->rlink)
{
printf("%d\n",p);
getch();
if(!p||p->size<n)
return 0;
else
{
f=footloc(p);
printf("%d\n",f);
getch();
pav=p->rlink;
printf("%d\n",pav);
getch();
if(p->size-n<=e)
{
if(pav==p)
{
pav=NULL;
printf("%d\n",pav);
getch();
}
else
{
pav->a.llink=p->a.llink;
p->a.llink->rlink=pav;
}
p->tag=f->tag=1;
}
else
{
f->tag=1;
p->size-=n;
f=footloc(p);
f->tag=0;
f->a.uplink=p;
p=f+1;
p->tag=1;
p->size=n;
}
}
}
free(p);
}
这个程序for循环之外运行不出来,请各位看看
#include"malloc.h"
#define footloc(p) (p)+(p)->size-1
#define max 1000
#define e 10
typedef struct word
{
union
{
struct word *llink;
struct word *uplink;
}a;
int tag;
int size;
struct word *rlink;
}word,head,foot,*space;
main()
{
space p,pav,f;
int n;
p=(word *)malloc(sizeof(word));
printf("%d\n",p);
getch();
pav=p+1;
pav->rlink=pav->a.llink=pav;
printf("%d\n",sizeof(word));
getch();
printf("%d\n",pav->rlink);
getch();
printf("%d\n",pav->a.llink);
getch();
pav->tag=0;
pav->size=max;
p=footloc(pav);
printf("%d\n",p);
getch();
p->a.uplink=pav;
printf("%d\n",p->a.uplink);
getch();
p->tag=0;
printf("%d\n",p+1);
getch();
(p+1)->tag=1;
n=300;
for(p=pav;p&&p->size<n&&p->rlink!=pav;p=p->rlink)
{
printf("%d\n",p);
getch();
if(!p||p->size<n)
return 0;
else
{
f=footloc(p);
printf("%d\n",f);
getch();
pav=p->rlink;
printf("%d\n",pav);
getch();
if(p->size-n<=e)
{
if(pav==p)
{
pav=NULL;
printf("%d\n",pav);
getch();
}
else
{
pav->a.llink=p->a.llink;
p->a.llink->rlink=pav;
}
p->tag=f->tag=1;
}
else
{
f->tag=1;
p->size-=n;
f=footloc(p);
f->tag=0;
f->a.uplink=p;
p=f+1;
p->tag=1;
p->size=n;
}
}
}
free(p);
}
这个程序for循环之外运行不出来,请各位看看