LoveUnix » 编程开发 & Rational » AIX中的结构体
让LU留住您的每

一天 让LU博客留住您的每一天
2005-11-22 20:19 finity
AIX中的结构体

在AIX编程中如定义
struct parent_inf
{
pid_t pid;
int max_child;
time_t start_time;
};
typedef struct
{
pid_t pid;
int status;
}
typedef struct
{
parent_inf pinf;
child_inf cinf[256];
}stScoreBoard;

然后定义变量
stScoreBoard *score_image;

score_image->pinf.pid  = -1;
在编译时时可能过的,但运行时就过不了
不知这个结构体该怎么正确使用,请各位不啬赐教,谢谢

2005-11-23 17:05 finity
stScoreBoard *score_image 改为stScoreBoard score_image

score_image->pinf.pid  = -1 改为score_image.pinf.pid  = -1

程序就可以运行,但不知结果如何,有待测试

2005-11-29 04:26 hsia
指向一个结构体,或者申请分配内存就好了。这是C的问题,不是AIX的


[code]
struct parent_inf
{
pid_t pid;
int max_child;
time_t start_time;
};
typedef struct
{
pid_t pid;
int status;
}
typedef struct
{
parent_inf pinf;
child_inf cinf[256];
}stScoreBoard;

stScoreBoard S_image;
stScoreBoard *score_image;

score_image=&S_image;
score_image->pinf.pid  = -1;

[/code]
这样就可以了。
只能对一个真实存在的结构体实例的成员赋值。

[[i] 本帖最后由 hsia 于 2005-11-29 04:35 编辑 [/i]]

页: [1]
查看完整版本: AIX中的结构体


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.