Chinaunix

标题: 请教一个编译错误 [打印本页]

作者: newtest12    时间: 2006-09-03 16:54
标题: 请教一个编译错误
我在的程序在编译的时候出现如下错误提示:
dereferencing pointer to incomplete type

我定义了这样一个结构
struct connect
{
     u_int32_t srcip;
}
struct connect *con;
con->srcip = inet_aton("192.168.11.1");//编译提示上面的错误。

请问该怎么解决啊?即使我将最后一句改为con->srcip = 200;也是一样的错误提示。
作者: 独孤九贱    时间: 2006-09-03 17:40
原帖由 newtest12 于 2006-9-3 16:54 发表
我在的程序在编译的时候出现如下错误提示:
dereferencing pointer to incomplete type

我定义了这样一个结构
struct connect
{
     u_int32_t srcip;
}
struct connect *con;
con->srcip = inet_a ...


1、你的指针能直接这样用???google 指针的用法……

2、
  1. inet_aton(将网络地址转成网络二进制的数字)  
  2. 相关函数  inet_addr,inet_ntoa

  3. 表头文件  #include<sys/scoket.h>
  4. #include<netinet/in.h>
  5. #include<arpa/inet.h>

  6. 定义函数  int inet_aton(const char * cp,struct in_addr *inp);

  7. 函数说明  inet_aton()用来将参数cp所指的网络地址字符串转换成网络使用的二进制的数字,然后存于参数inp所指的in_addr结构中。
  8. 结构in_addr定义如下
  9. struct in_addr
  10. {
  11. unsigned long int s_addr;
  12. };

  13. 返回值  成功则返回非0值,失败则返回0。
复制代码

作者: mrfan    时间: 2006-09-03 18:16
应该是这样吧
con->srcip = inet_addr("192.168.11.1");
作者: newtest12    时间: 2006-09-03 19:27
标题: 回复 1楼 newtest12 的帖子
当然我的指针是申请空间了,上面我将那步省略了,没有贴上来!
作者: jozn    时间: 2006-09-03 19:41
你用的inet_aton转成网络地址的函数对吗?

int inet_aton(const char *cp, struct in_addr *inp)
作者: snow_insky    时间: 2006-09-04 14:55
Your struct definition is error. You must add a ";" in the end.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2