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

header files contain prototypes for functions you define in a .c or .cpp/.cxx file (depending if you're using c or c++).

You want to place #ifndef/#defines around your .h code so that if you include the same .h twice in different parts of your programs, the prototypes are only included once

这本c语言的书不错,学习之,加油!!! http://publications.gbdirect.co.uk/c_book/chapter1/functions.html

参考: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的更多相关文章

  1. 【iOS】The differences between Class Extension and Header File 类扩展与头文件的区别

    . As the name suggests, they extend the class. A class continuation is another name. The class exten ...

  2. auto make System.map to C header file

    #!/bin/bash # auto make System.map to C header file # 说明: # 该脚本主要是将Linux内核生成的System.map文件中的符号.地址存入结构 ...

  3. c++预编译问题:fatal error C1083: Cannot open precompiled header file: 'Debug/DllTest.pch': No such file or d

    1)单独编译StdAfx.cpp 2)编译所有(即按Ctrl+F7) 这时因为该模块没有包括预编译头文件“stdafx.h”的缘故.VC用一个stdafx.cpp包含头文件stdafx.h,然后在st ...

  4. 进度记录 和 安装imagick时Cannot locate header file MagickWand.h错误的解决

    修改php.ini文件,已使php支持扩展的功能 [root@localhost imagick-2.2.2]# ./configure --with-php-config=/usr/local/ph ...

  5. fatal error C1083: Cannot open precompiled header file: 'Debug/xxoo.pch': No such file or directory

    fatal error C1083: Cannot open precompiled header file: 'Debug/xxoo.pch': No such file or directory ...

  6. About Why Inline Member Function Should Defined in The Header File

    About why inline member function should defined in the header file. It is legal to specify inline on ...

  7. Header File Dependencies

    [Header File Dependencies] 什么时候可以用前置声明替代include? 1.当 declare/define pointer&reference 时. 2.当 dec ...

  8. fatal error C1853: '<filename>' is not a precompiled header file

    当编译c和c++混合的项目时,会出现如下类似的错误 fatal error C1853: '<filename>' is not a precompiled header file 解决方 ...

  9. 原文:I don’t want to see another “using namespace xxx;” in a header file ever again

    http://stackoverflow.com/questions/5849457/using-namespace-in-c-headers http://stackoverflow.com/que ...

随机推荐

  1. IQueryable和IEnumerable,IList的区别

    IQueryable和IEnumerable都是延时执行(Deferred Execution)的,而IList是即时执行(Eager Execution) IQueryable和IEnumerabl ...

  2. 《JS权威指南学习总结--9.5 类和类型》

    内容要点: 介绍了三种用以检测任意对象的类的技术,instanceof运算符.constructor属性,以及构造函数的名字. 但每种技术都不甚完美,本节总结了鸭式辩型,这种编程哲学更加关注对象可以完 ...

  3. 遮盖层实现(jQuery+css+html)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  4. Modernizr 测试浏览器是否兼容相应属性

    Modernizr  测试浏览器是否兼容相应属性

  5. HTTP Request GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE Methods

    注:本文为个人学习摘录,原文地址为:http://javaeedevelop.iteye.com/blog/1725299 An HTTP request is a class consisting ...

  6. 七牛 在线管理 v0.1

    <?php // @codingStandardsIgnoreFile require_once __DIR__.'/../vendor/autoload.php'; use Qiniu\Aut ...

  7. PHP class which generates PDF files from UTF-8 encoded HTML

    http://www.mpdf1.com/mpdf/index.php

  8. spring配置文件详解【总结】

    知其然,知其所以然 <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns=&qu ...

  9. mysql、sqlserver数据库常见数据类型对应java中的的类型探究

    由于本次测试表的结构不涉及到主键的自增长,所以mysql.sqlserver建表语句相同: CREATE TABLE testType ( id INT NOT NULL DEFAULT 0, gen ...

  10. virtualbox+centos 7 实现宿主机器互通

    1.centos7iso文件 2.安装教程地址,www.aiplaypc.com/102.html 3.修改ip地址 使用命令 vi /etc/sysconfig/network-scripts/if ...