Creating your own header file in C

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

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


down vote

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

时间: 2024-11-04 16:10:14

Creating your own header file in C的相关文章

fatal error C1853: &#39;Debug/***.pch&#39; is not a precompiled header file created with this compiler

出现这个问题,把工程编译选项中的预编译去掉就可以了,操作步骤:首先全部重编译一下工程,如还是不行则试一试将工程设置中C/C++中precompiled   header中选中automatic   use   of   precompiled   headers,并在相应through   header中输入stdafx.h. 另外,rebuild all也是一种方法,或把debug目录下的文件删除,然后重新编译. fatal error C1853: 'Debug/***.pch' is no

auto make System.map to C header file

#!/bin/bash # auto make System.map to C header file # 说明: # 该脚本主要是将Linux内核生成的System.map文件中的符号.地址存入结构体中, # 目前认为也许可以在内核驱动中直接调用对应的函数.以前在学习裸板开发中就有 # 使用Uboot中提供的printf来写程序的先例,那么这里应该也是可以的,不过这里没 # 有什么实用性,因为5W个函数,但这个结构体就要用掉进200kByte空间. # # 2016-3-19 深圳 南山平山村

The differences between Class Extension and Header File 类扩展与头文件的区别

. As the name suggests, they extend the class. A class continuation is another name. The class extension is commonly used to declare private methods and properties. You want the class extension to be visible to the @implementation, and not in the hea

Creating a simple static file server with Rewrite--reference

Today, I’d like to take a quick moment to demonstrate how to make a simple file server using Rewrite, and any Servlet Container, such as Tomcat, Wildfly, or Jetty. This can enable much easier file updates for static content, such as preventing the ne

javah 生成header file 报错 问题解决

环境:Android Studio, Mac OS 目标: 用javah 为MainActivity.class 生成 jni header 文件 正确的命令是 cd <class文件的路径> javah -classpath :<jar包的路径>:. <class文件的包名+类名> ------示例 ----- cd app/build/intermediates/classes/debug javah -classpath :/Users/username/Libr

Creating a PXE Configuration File

  The PXE configuration file defines the menu displayed to the pxe client host as it boots up and contacts the TFTP server. You need a PXE configuration file for PXE. The TFTP server is always listening for PXE clients on the network. When it detects

Keil AGDI Header File

#ifndef __AGDI__INCED___ #define __AGDI__INCED___ //---Revision History: ---------------------------------------------- // 17.10.2000, added AG_SYM_SFR // //------------------------------------------------------------------- #ifdef __cplusplus extern

Generate C and C++ Header File

1. 2. 其中bootclasspath 后面的参数就是自己android.jar具体位置 location: ${system_path:javah} working Directoy: ${project_loc}/jni Arguments: -d "${project_loc}/jni/" -classpath  "${project_classpath};" -bootclasspath "E:/DEV/Android/android-sdk/

c a header file realize of multiple .c file

//I write a few variables declaration,then include this head-file in multiple realization-c-file,then appear "multiple definition of 'var1 ' " error resolution: exists-file:myhead.h,realize1.c,realize2.c,main.c add:myhead.c 1.move the defintion-