【问题标题】:warning: incompatible pointer types警告:不兼容的指针类型
【发布时间】:2013-04-04 11:48:51
【问题描述】:

关注我之前的question:

现在我有了这个:

xml_list *text1(xml_list *);
xml_list *text(xml_list *);

//operation: text1(elem)
xml_list *text1(xml_list *elem){
  if(isText(elem)){
    return Cons(elem,Nil());
  }
  else{
    return text(childeren(elem));
  }
}

//operation: text(elem)
xml_list *text(xml_list *elem){
  if(isEmpty(elem)){
    return Nil();
  }
  return append(text1(head(elem)),text(tail(elem)));
}

当我运行它时,我会收到 xml_list *text1 的警告:

incompatible pointer types passing 'xml_list *' (aka 'struct xml_list_struct *') to parameter of type 'xml *' (aka 'struct xml_struct *') [-Wincompatible-pointer-types]
 if(isText(elem)){

还有下一行的警告:

warning: incompatible pointer types passing 'xml_list *' (aka 'struct xml_list_struct *') to parameter of type 'xml *' (aka 'struct xml_struct *') [-Wincompatible-pointer-types]
 return Cons(elem,Nil());

再次警告:

    warning: incompatible pointer types passing 'xml_list *' (aka 'struct xml_list_struct *') to parameter of type 'xml *' (aka 'struct xml_struct *') [-Wincompatible-pointer-types]
 return text(children(elem));

我怎样才能让这些警告消失??

【问题讨论】:

  • 那么,isEmpty()Cons()children() 的原型是什么?它们显然与您传递的论点不相容。你需要解决这个问题。
  • isEmpty(xml_list *elems) 及其返回 int。 Cons(xml *hd, xml_list *tl) 它返回 xml_list。 children(xml *elem) 并返回 xml_list。

标签: c xml


【解决方案1】:

错误是不言自明的:

您的isTextConschildren 方法需要xml*(指向xml_struct 的指针)。您正在传递一个xml_list*(指向xml_list_struct 的指针)。

您可以通过传递正确的指针 (xml*) 或修复方法以接受您拥有的指针 (xml_list*) 来消除警告

【讨论】:

    猜你喜欢
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多