终于跑起来了,含自定义 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. 第一百节,JavaScript表达式中的运算符

    JavaScript表达式中的运算符 学习要点: 1.什么是表达式 2.一元运算符 3.算术运算符 4.关系运算符 5.逻辑运算符 6.*位运算符 7.赋值运算符 8.其他运算符 9.运算符优先级 E ...

  2. Dubbo入门实例 本地伪集群测试Demo

    1.   概述 Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案 Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提 ...

  3. 【解题报告】瑞士轮(NOIP2011普及组T3)

    [题外话:这道题吧……说实话我不太喜欢……因为卡快排.] 题目不贴了,就是给你一个赛制,然后各个选手的初始得分和能力值,问你进行R轮比赛之后第Q名的编号是多少(这个编号读进来就要算OYZ,初始快排的时 ...

  4. hdu_5874_Friends and Enemies(公式题)

    题目链接:hdu_5874_Friends and Enemies 题意: 有nn个人, mm种颜色的石头, 人两两之间要么是朋友, 要么是敌人. 每个人可以携带若干种石头或者不带, 要求朋友之间至少 ...

  5. IOS 类似网易新闻客户端内容滚动菜单跟随居中组件

    需求分析: 1.类似网易新闻客户端页面滚动组件.菜单栏对应菜单项一直居中 2.点击菜单栏可以切换到对应的page 3.滑动页面可以自动切换相应的菜单.并且对应的菜单栏居中显示 4.初始化时可以自定义菜 ...

  6. SERVICE_USE_PID

    openwrt中启动脚本中经常出现如下一句: SERVICE_USE_PID=1 例如 lldp启动脚本 lldpd.init中如下: #!/bin/sh /etc/rc.common # Copyr ...

  7. Ubuntu环境变量——系统变量和用户变量

    系统变量: 对所有用户有效果 /etc/profile /etc/environment 两个命令只用一个就可以,原则上是重启后修改生效,但是经过验证可以通过执行以下命令实现: source /etc ...

  8. The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

    消息筛选器显示应用程序正在使用中. ((错误来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) 在对Word文档进行合并或者其他操作的时候,如果数 ...

  9. 洛谷-陶陶摘苹果(升级版)-BOSS战-入门综合练习1

    题目描述 Description 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他手够不着时,他会站到椅子上再试试. 这次与NOIp2005普及组第一题不同 ...

  10. java代码块 静态、非静态

    Java虚拟机的内存分区:Java栈.堆.方法区.本地方法栈.PC寄存器.还有一个常量池的概念,虚拟机会为每种类型分配一个常量池,而不是实例. 例如有一个类有很多子类,那么在父类定义的final变量, ...