我有一个C程序(基于链表的商店数据库,每个商店都有一个子链接列表的产品)。我把我的项目分割成.h和.c文件。这是我应该这样做的正确方法吗?
我有4个.c文件:
-> interface.c //functions for interface | #include interface.h
-> products.c // funcs for managing product list | #include products.h
-> shop.c // funcs for managing shop list | #include shop.h
-> main.c // int main(); only | #include main.h
我有4个.h文件:
-> interface.h // prototypes from interface.c | #include main.h
-> products.h // prototypes from products.c | #include main.h
-. shop.h // prototypes from shop.c | #include main.h
-> main.h (I put there my global constants from #define, enum and structs from shop linked list and product sub linked list and standard libraries like stdio etc.)
BTW。项目工作,但在main.c()Visual Studio强调每个函数。 这是我将项目分成.c和.h文件的正确方法吗?
每个头文件应该是第一个包含在每个.c文件中......这将测试它们的一致性,并确保在使用它们之前定义所有(非静态)函数。 –
@JumBalter,好吧,现在是否应该将main.h添加到每个.c文件?否则它不工作:/ – tomdavies
确定它是正确的,但它已包含在其他头文件中。想必你使用的是守卫。如果某些东西不能正常工作,则需要更清楚地知道发生了什么问题。 –