C- assignment from incompatible pointer type?
网上搜了好多报这种warning的,但都没有我的这些奇怪,求大神指教。
#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int Coefficient;
int Exponent;
struct Node *next;
} Node;
typedef struct _list {
Node * head;
} List;
void insert(List * pList, int coeff, int expon);
void print(const List *pList);
int main()
{
List list1, list2, listSum, listProd;
list1.head = NULL;
list2.head = NULL;
listSum.head = NULL;
listProd.head = NULL;
int n, m;
int i;
int coeff, expon;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &coeff, &expon);
insert(&list1, coeff, expon);
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d %d", &coeff, &expon);
insert(&list2, coeff, expon);
}
print(&list1);
print(&list2);
return 0;
}
void insert(List * pList, int coeff, int expon)
{
Node *p = (Node *)malloc(sizeof(Node));
p->Coefficient = coeff;
p->Exponent = expon;
p->next = NULL;
Node *last = pList->head;
if (last) {
while (last->next) {
last = last->next; //[Warning] assignment from incompatible pointer type
}
last->next = p; //[Warning] assignment from incompatible pointer type
}
else {
pList->head = p;
}
}
void print(const List *pList)
{
Node *p;
for (p = pList->head; p; p = p->next) { //[Warning] assignment from incompatible pointer type
printf("%d %d", p->Coefficient, p->Exponent);
if (p->next) {
printf(" ");
}
}
printf("\n");
}
dev gcc4.9.2 报warning,但是为什么报warning呢?
求大神指教:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
变异只报warning:
test.c: In function ‘insert’:
test.c:49:18: warning: assignment from incompatible pointer type [enabled by default]
test.c:51:20: warning: assignment from incompatible pointer type [enabled by default]
test.c: In function ‘print’:
test.c:61:32: warning: assignment from incompatible pointer type [enabled by default]
执行也没有出现错误