开发者社区> 问答> 正文

请问 C- assignment from incompatible pointer type?

#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呢?
求大神指教:)

展开
收起
杨冬芳 2016-05-30 17:34:58 6236 0
1 条回答
写回答
取消 提交回答
  • IT从业

    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

    执行无错误

    2019-07-17 19:20:50
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
AVPASS:Automatically Bypassing 立即下载
AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically 立即下载
Separating hot-cold data into heterogeneous storage based on layered compaction 立即下载