创建使用C你自己的头文件 [英] Creating your own header file in C
本文介绍了创建使用C你自己的头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能解释如何创建在C头文件,从开始到结束一个简单的例子。
Can anyone explain how to create a header file in C with a simple example from beginning to end.
推荐答案
foo.h中
#ifndef FOO_H_ /* Include guard */
#define FOO_H_
int foo(int x); /* An example function declaration */
#endif // FOO_H_
foo.c的
#include "foo.h" /* Include the header (not strictly necessary here) */
int foo(int x) /* Function definition */
{
return x + 5;
}
的main.c
#include <stdio.h>
#include "foo.h" /* Include the header here, to obtain the function declaration */
int main(void)
{
int y = foo(3); /* Use the function here */
printf("%d\n", y);
return 0;
}
要编译使用GCC
gcc -o my_app main.c foo.c
这篇关于创建使用C你自己的头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文