终于跑起来了,含自定义 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. ubuntu通过tnvm安装Nodejs

    第一步,先安装tvm tnvm(Taobao Node Version Manager)淘宝Node版本管理器 安装: 直接输入 wget -O- https://raw.githubusercont ...

  2. linshi_temp_erweima_html

    <!doctype html><html><head><meta charset="utf-8"><meta content= ...

  3. java 邮件发送 apache commons-email

    package com.sun.mail;import org.apache.commons.mail.Email;import org.apache.commons.mail.EmailExcept ...

  4. LeetCode OJ 162. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  5. Rational Rose 2003 逆向工程转换C++ / VC++ 6.0源代码成UML类图

    目录 1.安装&破解Rational Rose 2003 1.1 安装Rose 2003 1.2 破解Rose 2003 1.3运行出错“没有找到suite objects.dl” 2. Ra ...

  6. java虚拟机存储区

    方法区和堆区是数据共享区. 栈区:数据不共享.方法参数.局部变量.参与运算的中间结果.返回值等等都在栈区中. 堆区:数据共享.存放对象. 方法区存放类型信息,类型信息包括:字段信息.方法信息.该类型的 ...

  7. RegOpenKey(注册表定位器) 1.5 中文免费绿色版

    软件名称: RegOpenKey(注册表定位器) 1.5 中文免费绿色版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win7 / Vista / Win2003 / WinXP / Wi ...

  8. C - 小Y上学记——认识新同学

    C - 小Y上学记——认识新同学 Time Limit: 4000/2000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) ...

  9. Ubuntu iptalbes 保存配置

     ubuntu 保存防火墙命令,iptables方式:1.iptables 配置好策略2.iptables-save > /etc/network/iptables.up.rules ,配置的策 ...

  10. js 鸭式辨型法

    无意中看到arr.length === +arr.length;这句代码,然后就去了解了下 这是一种鸭式辨型的判断方法. 鸭式辨型:像鸭子一样走路.游泳和嘎嘎叫的鸟就是鸭子 这句话表示: a.arr有 ...