结构指针的问题(在线等)

messinglong 2003-08-21 01:52:50
我定义了两个结构如下:
typedef struct test1_struct {
int file_descriptor;
} test1;
1typedef struct test2_struct {
2
3 int statement_id;
4 struct test1 * test;
5 char * execommand;
6
7} test2;
8
9int main(){
10int fd;
11test2 *newtest;
12newtest = (test2*)(参数1);
13fd = newtest->test->file_descriptor;
........}
编译出错:13,dereferencing pointer to incomplete type
这条出错是啥意思?请问如何解决
...全文
110 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
fancy123 2003-08-21
  • 打赏
  • 举报
回复
char * command;
strcpy(command , newtest->execommand);

没有为Command指针分配空间

sevecol 2003-08-21
  • 打赏
  • 举报
回复
c的话调用malloc给指针分配空间。
六月初六 2003-08-21
  • 打赏
  • 举报
回复
typedef struct test1_struct {
int file_descriptor;
} test1;
typedef struct test2_struct {

int statement_id;
struct test1 * test;
//这里好像不能这样写 test1已经是一个类型了
//这里要么这么写test1 *test;要么 struct test1_struct *test
char * execommand;

} test2;

int main(){
int fd;
test2 *newtest;
newtest = (test2*)(参数1);//这里就不知所云了 望请高人指教
//感觉你好像是强制转换了一个参数! 摆脱写全好么!
fd = newtest->test->file_descriptor;
........}
messinglong 2003-08-21
  • 打赏
  • 举报
回复
to wbh0360
相同啊
wbh0360 2003-08-21
  • 打赏
  • 举报
回复
12newtest = (test2*)(参数1);

你那个‘参数1’结构与test2同吗?!
messinglong 2003-08-21
  • 打赏
  • 举报
回复

因为还需要别的函数库所以贴出来很麻烦,你们可以看一下下面的:
int Execute(HSTMT StatementHandle){

test2 * newtest;

newtest = (test2*)(StatementHandle);

int ret;

int fd;

char response[65535];

char * command;

strcpy(command , newtest->execommand);

fd = newtest->test->file_descriptor;
//这里要调用的其他的函数
if (ret = otherexec(fd,command,response,65535)<0){

debug_write("otherexec fail");

}
return (0);
}
Dragon132 2003-08-21
  • 打赏
  • 举报
回复
楼主把整个程序贴出来啊,给我们直接调试就行了
messinglong 2003-08-21
  • 打赏
  • 举报
回复
to serecol
请问,那么字符窜的赋值是不是可以这样写

strcpy(newcommand,newtest->execommand);
好像有问题啊
messinglong 2003-08-21
  • 打赏
  • 举报
回复
to serecol
c 没有这样的啊
newtest->test = new test1;
sevecol 2003-08-21
  • 打赏
  • 举报
回复
可以。

你的问题可能是内存的问题,你没有为test2中的test1分配内存,直接去取数据行为是未知的。
messinglong 2003-08-21
  • 打赏
  • 举报
回复
请问可以这样赋值吗??
int fd ;

fd = newtest->test->file_descriptor;

是不是要用别的形式呢?

sevecol 2003-08-21
  • 打赏
  • 举报
回复
执行出错,可能使用为没有分配内存,你需要
newest->test=new test1;
sevecol 2003-08-21
  • 打赏
  • 举报
回复
没分配空间不会产生编译错误。

按照Dragon132(Dragon)方法该应该就可以了。
messinglong 2003-08-21
  • 打赏
  • 举报
回复
to dragon
还是不行啊,编译通过,执行出错
to jack_wq
你的newtest->test = pp;是啥意思,我是要
fd = newtest->test->file_descriptor啊
messinglong 2003-08-21
  • 打赏
  • 举报
回复
楼上的
哪里没有调用情说明一下,是指test需要申请吗?该如何申请空间?请详细说明?
jack_wq 2003-08-21
  • 打赏
  • 举报
回复
你可以这样:
test1 *pp=new sizeof(test1);
if(pp!=NULL)
newtest->test=pp;
Dragon132 2003-08-21
  • 打赏
  • 举报
回复
1typedef struct test2_struct {
2
3 int statement_id;
4 struct test1_struct * test; //这里改一下或用test1 * test;
5 char * execommand;
6
7} test2;
messinglong 2003-08-21
  • 打赏
  • 举报
回复
楼上的:
只是说明我的结构newtest已经初始化,你可以看成是如下的形式
newtest = (test2*)(connHandle);
jack_wq 2003-08-21
  • 打赏
  • 举报
回复
fd = newtest->test->file_descriptor;
test是test1结构的指针,可是上句调用的时候没有申请内存空间!
sevecol 2003-08-21
  • 打赏
  • 举报
回复
12newtest = (test2*)(参数1);

这一行是什么啊?

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧