简体   繁体   English

多文件C程序

[英]Multi File C Programs

I am trying to create a multifile c program, I am using a function in one file that I want to call again from another file, how do I do this without making either of the files header files? 我正在尝试创建一个多文件C程序,我正在一个文件中使用一个函数,我想从另一个文件中再次调用该函数,如何在不创建任何文件头文件的情况下执行此操作? Can I use function prototypes for this? 我可以为此使用函数原型吗?

In order to use functions defined in another file, you must use a header file, but you don't convert your .c files to header files, you include the function prototypes needed by one particular class (file) in the header file, and then include that header file in each file. 为了使用在另一个文件中定义的函数,必须使用头文件,但不要将.c文件转换为头文件,而是在头文件中包含一个特定类(文件)所需的函数原型,并且然后在每个文件中包含该头文件。

calc.h
calc.c <---- include calc.h

main.c <---- include calc.h

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

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