当前位置: 技术问答>linux和unix
想建立一个指向结构体的指针数组,但编译不过,望高手指点!
来源: 互联网 发布时间:2015-12-06
本文导语: 代码如下: typedef struct listen { char Cookie; long RequestTimeStamp; long RequestFileSize; struct listen *left, *right ; }listenqueue; struct listen *h1=NULL, *h2=NULL, *h3=NULL; struct listen *h4=NULL, *h5=NULL, *h6=NULL, *h7=NULL ; struct list...
代码如下:
typedef struct listen
{
char Cookie;
long RequestTimeStamp;
long RequestFileSize;
struct listen *left, *right ;
}listenqueue;
struct listen *h1=NULL, *h2=NULL, *h3=NULL;
struct listen *h4=NULL, *h5=NULL, *h6=NULL, *h7=NULL ;
struct listen *his[7] = { h7, h1, h2, h3, h4, h5, h6 };
编译错误是:
error:initializer element is not constant!
typedef struct listen
{
char Cookie;
long RequestTimeStamp;
long RequestFileSize;
struct listen *left, *right ;
}listenqueue;
struct listen *h1=NULL, *h2=NULL, *h3=NULL;
struct listen *h4=NULL, *h5=NULL, *h6=NULL, *h7=NULL ;
struct listen *his[7] = { h7, h1, h2, h3, h4, h5, h6 };
编译错误是:
error:initializer element is not constant!
|
既然都是空的,为什么还要struct listen *his[7] = { h7, h1, h2, h3, h4, h5, h6 };
改为:struct listen *his[7] = { NULL, NULL,NULL, NULL, NULL, NULL, NULL };不是很明白搂住的用意
改为:struct listen *his[7] = { NULL, NULL,NULL, NULL, NULL, NULL, NULL };不是很明白搂住的用意
|
*his[7]在定义时直接初始化的话,里面的值必须是常量,不能是变量。可以先定义his,然后把 h7, h1, h2, h3, h4, h5, h6 再赋予his