简体   繁体   中英

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

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 is case sensitive. Struct should be struct .

The way to go with structs in C is

  1. Don't bother with typedefs for structs, they are useless and only save you typing the struct keyword
  2. Declare the struct in a public header file and #include it only in files needing the struct . In other words, write a proper interface and place the interface declaration in the header, the interface implementation in a C file.

You need to define your structs in .h files that you include where the struct is used.

Unknown type name "list" on sorting.h tries to tell you that while processing sorting.h the list is unknown.

You can also shorten ist definition by combining typedef + struct.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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