首页 > 其他 > 详细

Creating your own header file in C

时间:2016-12-21 11:33:53      阅读:223      评论:0      收藏:0      [点我收藏+]

终于跑起来了,含自定义 include .h 的c语言程序,超开心呀!

 

参考: http://stackoverflow.com/questions/7109964/creating-your-own-header-file-in-c

 

 

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;
}

To compile using GCC

gcc -o my_app main.c foo.c

Creating your own header file in C

原文:http://www.cnblogs.com/oxspirt/p/6207053.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!