【发布时间】:2014-11-23 20:37:36
【问题描述】:
我正在为一个班级做一个项目,需要帮助将我的程序分成几个部分。我的老师给了我们一个提示,说明哪些文件会做什么,但他没有告诉我们如何编写头文件。根据我在网上学到的知识,我将每个 .c 文件中的函数原型放入其自己的 .h 文件中,并将它们与“header.h”一起包含在 .c 文件中。但是,我收到编译错误,例如
course1.c:20:3: warning: implicit declaration of function ‘initialize’ [-Wimplicit-function-declaration]
initialize(courses, subjects, CRN);
^
vector1.c:14:6: error: conflicting types for ‘resize’
void resize(char ***courses, char***subjects, int **CRN) {
^
In file included from vector1.c:2:0:
vector.h:11:6: note: previous declaration of ‘resize’ was here
void resize(char ***subjects, char ***courses, int **CRNs, int *size);
^
vector1.c:39:6: error: conflicting types for ‘deallocate’
void deallocate(char **courses, char**subjects, int *CRN) {
^
In file included from vector1.c:2:0:
vector.h:12:6: note: previous declaration of ‘deallocate’ was here
void deallocate(char **subjects, char **courses, int *CRNs, int size);
我很确定我的文件具有正确的语法,因为我将它们分别编译成 .o 文件并且它们运行良好。有人可以概括地说,如何将程序分成单独的文件?我想我显然做错了。编译器给我的一个错误是一个函数没有定义,当它在我包含的头文件中明确定义时。
【问题讨论】:
-
请格式化您的问题:)(在突出显示代码元素后使用页面顶部的 { } 按钮)以帮助提高可读性,因为目前很难阅读。
-
如果您阅读编译错误,您会看到存在冲突的函数减速。
resize和deallocate函数在vector.h和vector1.c中定义不同。initialize函数有一个警告,这意味着在定义它之前使用调用了该函数。这是一个警告,而不是编译错误。
标签: c file header makefile modular