C- assignment from incompatible pointer type?

发布于 2022-09-02 10:22:10 字数 1761 浏览 56 评论 0

网上搜了好多报这种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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2022-09-09 10:22:10

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]

         last = last->next;  //[Warning] assignment from incompatible pointer type
              ^

test.c:51:20: warning: assignment from incompatible pointer type [enabled by default]

     last->next = p;   //[Warning] assignment from incompatible pointer type
                ^

test.c: In function ‘print’:
test.c:61:32: warning: assignment from incompatible pointer type [enabled by default]

 for (p = pList->head; p; p = p->next) {     //[Warning] assignment from incompatible pointer type
      

执行也没有出现错误

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文