指针链表能用数组方式访问吗?神奇呀
kzy04 2007-09-06 01:26:22 各位大侠:有段代码好像是指针链表能用数组方式访问,求解惑:
注:以下引用的程序为p2p开源项目源码,代码本身没有问题,编译后可正常运行。
1、变量类型定义
struct ServerDesc
{
int flag;
int sock;
int type;
int cur;
int max;
int maxid;
struct Session *head;
int (*init) (int listnum);
int (*process) (int listnum);
int (*closure) (int listnum);
};
struct Session
{
int type;
int socket;
unsigned int host;
unsigned int port;
unsigned int numjob;
struct JobDes *head;
struct Channel *pc;
struct Edge *header;
struct Session *next;
};
struct ServerDesc TRACKER[MAX_TYPE];
2、部分代码段
while (TRACKER[type].maxid == listnum && TRACKER[type].head[listnum].socket == 0 && listnum > 0)
{
listnum --;
TRACKER[type].maxid --;
}
3、我的问题
在serverdesc定义中head定义为struct Session *head;
head没有被定义成数组呀,怎么可以当数组用呀?
谢谢赐教!!