c - 链接列表不兼容的指针类型

标签 c pointers struct

我不明白为什么将“root”分配给等于“trieu”会是一个不兼容的指针:/

#include <stdio.h>
#include <stdlib.h>

struct uniform {
    char size;
    int number;
    struct uniform *ext;
};

struct uniform *trieu;
struct unifrom *root;

int main(void) {
    trieu = malloc(sizeof(struct uniform));
    root = trieu;
...
    trieu = root;

当我用 gcc 编译它时,它给我:

program.c: In function ‘main’:
program.c:15:7: warning: assignment from incompatible pointer type
  root = trieu;
   ^
program.c:57:8: warning: assignment from incompatible pointer type
  trieu = root;

它之前在我制作的另一个程序中有效:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct ll {
    char store;
    struct ll *ext;
};

struct ll *trieu;
struct ll *root;

int main(int argc, char* argv[]) {
    trieu = malloc(sizeof(struct ll));
    root = trieu;
...

最佳答案

你打错了。使用 struct uniform *root; 而不是 struct unifrom *root;

关于c - 链接列表不兼容的指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34100717/

相关文章:

char* 来自 char[] 结构成员

c - 将 typedef 结构作为参数传递给函数

C 程序省略字符

c - 使用并行任务减少 OpenMP

c - 返回结果和通过指针参数分配结果之间的区别?

c++ - 将对象的指针添加到链表c++

c - GCC Atomic Builtins 而不是 pthread?

c - 在扁平多维数组中检测 "rank of corner"的有效方法

c++ - OpenCV Tracker 属性访问在 ARM 上使用 SEGFAULT 失败,但在 X86_64 中有效

c - 在 C 中动态创建单链表