简体   繁体   English

C程序上的未知类型名称“列表”

[英]Unknown type name “list” on C program

i had problem to split program on more files .c and .h on main.ci put a struct like 我在将文件拆分到更多文件.c和main.ci上的.h时遇到问题

struct listnumbers {
  float number;
  struct listnumbers *next;
};typedef struct listnumbers *list;

the problem come when i need to compile all files .c .h and compilator give me an error like Unknown type name "list" on sorting.h = void sorting(list *pt,float number) 当我需要编译所有文件时,问题就来了。c .h和编译器在sorting.h =无效排序(列表* pt,浮点数)上给我一个类似未知类型名称“列表”的错误

C is case sensitive. C区分大小写。 Struct should be struct . Struct应该是struct

The way to go with structs in C is 在C中使用结构的方法是

  1. Don't bother with typedefs for structs, they are useless and only save you typing the struct keyword 不要为结构体的typedef烦恼,它们是无用的,只会节省您键入struct关键字的时间
  2. Declare the struct in a public header file and #include it only in files needing the struct . 在公共头文件中声明该结构,并仅在需要该struct文件中#include它。 In other words, write a proper interface and place the interface declaration in the header, the interface implementation in a C file. 换句话说,编写一个适当的接口并将接口声明放在标头中,并将接口实现放在C文件中。

You need to define your structs in .h files that you include where the struct is used. 您需要在.h文件中定义结构,其中包括使用结构的位置。

Unknown type name "list" on sorting.h tries to tell you that while processing sorting.h the list is unknown. sorting.h上的未知类型名称“ list”试图告诉您在处理sorting.h list是未知的。

You can also shorten ist definition by combining typedef + struct. 您还可以通过组合typedef + struct来缩短ist定义。

typedef struct listnumbers {
  float number;
  struct listnumbers *next;
} *list;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM