【问题标题】:C: error: dereferencing pointer to incomplete typeC:错误:取消引用指向不完整类型的指针
【发布时间】:2013-02-16 05:14:01
【问题描述】:

我收到一个错误(错误:取消引用指向不完整类型的指针 ) 与 addData->s = s 和 addData->type = type,我不知道为什么......它似乎对我有用(但是我对 C 有点生疏)

代码如下:

int addSym(char *s, var_type type){
    struct syment* addData=  malloc(sizeof(syment));
    addData->s = s;
    addData->type = type;

...

我喜欢

typedef struct syment_s {
  char *s;
  int offset;
  var_type type;
  struct syment_s *next;
}*syment;

谢谢!

【问题讨论】:

标签: c pointers struct


【解决方案1】:

尝试改变

typedef struct syment_s {
  char *s;
  int offset;
  var_type type;
  struct syment_s *next;
}*syment;

typedef struct syment_s {
  char *s;
  int offset;
  var_type type;
  struct syment_s *next;
} syment;

指针过载,这不是 Crufts(指针是狗,Crufts 是狗表演)。

【讨论】:

  • 谢谢!那并删除 struct syment* addData= malloc(sizeof(syment)); 中的结构工作,谢谢!我被告知要使用 syment,以便以后可以使用 syment...猜那是错误的!
  • 谢谢!它说我必须等一分钟才可以(这里是 n00b)
  • @winepretzel - 忘了提 - 保持明确的指针 - 如果你知道你正在处理指针,从长远来看可以节省很多麻烦。
猜你喜欢
  • 2018-05-31
  • 2017-11-02
  • 2011-04-06
  • 1970-01-01
  • 1970-01-01
  • 2016-07-12
  • 2018-04-09
相关资源
最近更新 更多