当前位置: 首页 > news >正文

北京冬奥会网站制作素材深圳网络营销推广专员

北京冬奥会网站制作素材,深圳网络营销推广专员,中国互联网信息中心,免费咨询标志C 语言头文件 头文件是扩展名为 .h 的文件,包含了 C 函数声明和宏定义,被多个源文件中引用共享。有两种类型的头文件:程序员编写的头文件和编译器自带的头文件。 在程序中要使用头文件,需要使用 C 预处理指令 #include 来引用它…

C 语言头文件

头文件是扩展名为 .h 的文件,包含了 C 函数声明和宏定义,被多个源文件中引用共享。有两种类型的头文件:程序员编写的头文件和编译器自带的头文件。

在程序中要使用头文件,需要使用 C 预处理指令 #include 来引用它。前面我们已经看过 stdio.h 头文件,它是编译器自带的头文件。

引用头文件相当于复制头文件的内容,但是我们不会直接在源文件中复制头文件的内容,因为这么做很容易出错,特别在程序是由多个源文件组成的时候。

A simple practice in C 或 C++ 程序中,建议把所有的常量、宏、系统全局变量和函数原型写在头文件中,在需要的时候随时引用这些头文件。

引用头文件的语法

使用预处理指令 #include 可以引用用户和系统头文件。它的形式有以下两种:

#include <file>

这种形式用于引用系统头文件。它在系统目录的标准列表中搜索名为 file 的文件。在编译源代码时,您可以通过 -I 选项把目录前置在该列表前。

#include "file"

这种形式用于引用用户头文件。它在包含当前文件的目录中搜索名为 file 的文件。在编译源代码时,您可以通过 -I 选项把目录前置在该列表前。

引用头文件的操作

#include 指令会指示 C 预处理器浏览指定的文件作为输入。预处理器的输出包含了已经生成的输出,被引用文件生成的输出以及 #include 指令之后的文本输出。例如,如果您有一个头文件 header.h,如下:

char *test (void);

和一个使用了头文件的主程序 program.c,如下:

int x;
#include "header.h"
int main (void)
{puts (test ());
}

编译器会看到如下的代码信息:

int x;
char *test (void);
int main (void)
{puts (test ());
}

只引用一次头文件

如果一个头文件被引用两次,编译器会处理两次头文件的内容,这将产生错误。为了防止这种情况,标准的做法是把文件的整个内容放在条件编译语句中,如下:

#ifndef HEADER_FILE
#define HEADER_FILE
the entire header file file
#endif

这种结构就是通常所说的包装器 #ifndef。当再次引用头文件时,条件为假,因为 HEADER_FILE 已定义。此时,预处理器会跳过文件的整个内容,编译器会忽略它。

有条件引用

有时需要从多个不同的头文件中选择一个引用到程序中。例如,需要指定在不同的操作系统上使用的配置参数。您可以通过一系列条件来实现这点,如下:

#if SYSTEM_1# include "system_1.h"
#elif SYSTEM_2# include "system_2.h"
#elif SYSTEM_3...
#endif

但是如果头文件比较多的时候,这么做是很不妥当的,预处理器使用宏来定义头文件的名称。这就是所谓的有条件引用。它不是用头文件的名称作为 #include 的直接参数,您只需要使用宏名称代替即可:

 #define SYSTEM_H "system_1.h"...#include SYSTEM_H

SYSTEM_H 会扩展,预处理器会查找 system_1.h,就像 #include 最初编写的那样。SYSTEM_H 可通过 -D 选项被您的 Makefile 定义。


文章转载自:
http://dinncoinlet.tqpr.cn
http://dinncogivey.tqpr.cn
http://dinncocodicology.tqpr.cn
http://dinncomycelia.tqpr.cn
http://dinncosmuggling.tqpr.cn
http://dinncorenitent.tqpr.cn
http://dinncooverbuy.tqpr.cn
http://dinncopreemptive.tqpr.cn
http://dinncopollster.tqpr.cn
http://dinncodermatropic.tqpr.cn
http://dinncodifficult.tqpr.cn
http://dinncoacidosis.tqpr.cn
http://dinncomalevolence.tqpr.cn
http://dinncoyardbird.tqpr.cn
http://dinncostriped.tqpr.cn
http://dinncogrig.tqpr.cn
http://dinncoacupressure.tqpr.cn
http://dinncopostmillennial.tqpr.cn
http://dinncoevenminded.tqpr.cn
http://dinncobertha.tqpr.cn
http://dinncophonomania.tqpr.cn
http://dinncoantsy.tqpr.cn
http://dinncodinghy.tqpr.cn
http://dinncoyeanling.tqpr.cn
http://dinncojoyance.tqpr.cn
http://dinncochinee.tqpr.cn
http://dinncoturkeytrot.tqpr.cn
http://dinncofather.tqpr.cn
http://dinncohyperuricaemia.tqpr.cn
http://dinncountruthful.tqpr.cn
http://dinncosuperciliary.tqpr.cn
http://dinncocontumacious.tqpr.cn
http://dinncothoria.tqpr.cn
http://dinncourotropine.tqpr.cn
http://dinncomellitum.tqpr.cn
http://dinncocalcutta.tqpr.cn
http://dinncoadvantageously.tqpr.cn
http://dinncoyellowbird.tqpr.cn
http://dinncocontain.tqpr.cn
http://dinncosuperplasticity.tqpr.cn
http://dinncoinveigh.tqpr.cn
http://dinncononage.tqpr.cn
http://dinncokazakh.tqpr.cn
http://dinncocomandante.tqpr.cn
http://dinncooversleep.tqpr.cn
http://dinncorevisionary.tqpr.cn
http://dinncomissus.tqpr.cn
http://dinncoexaminator.tqpr.cn
http://dinncopellitory.tqpr.cn
http://dinncoleishmanial.tqpr.cn
http://dinncosyndactylous.tqpr.cn
http://dinncosquirrel.tqpr.cn
http://dinncocheechako.tqpr.cn
http://dinncofootrest.tqpr.cn
http://dinncobidet.tqpr.cn
http://dinncoamildar.tqpr.cn
http://dinncohemotoxic.tqpr.cn
http://dinncodistill.tqpr.cn
http://dinncotransection.tqpr.cn
http://dinncoproposition.tqpr.cn
http://dinncojarful.tqpr.cn
http://dinncoapocalypticist.tqpr.cn
http://dinncorubberneck.tqpr.cn
http://dinnconowhither.tqpr.cn
http://dinncorubber.tqpr.cn
http://dinncorhetic.tqpr.cn
http://dinncobodgie.tqpr.cn
http://dinncostook.tqpr.cn
http://dinncorutilant.tqpr.cn
http://dinncohydropsy.tqpr.cn
http://dinncopostmortem.tqpr.cn
http://dinncospeechifier.tqpr.cn
http://dinncoimpoliticly.tqpr.cn
http://dinncoparamaribo.tqpr.cn
http://dinncobureaux.tqpr.cn
http://dinncodishoard.tqpr.cn
http://dinncochutzpa.tqpr.cn
http://dinncocamion.tqpr.cn
http://dinncodudder.tqpr.cn
http://dinncocosurveillance.tqpr.cn
http://dinncogranth.tqpr.cn
http://dinncobeetlebung.tqpr.cn
http://dinncoclanism.tqpr.cn
http://dinncopyralid.tqpr.cn
http://dinncohalachist.tqpr.cn
http://dinncokiller.tqpr.cn
http://dinncocorneoscleral.tqpr.cn
http://dinncocommotion.tqpr.cn
http://dinncocoryphaeus.tqpr.cn
http://dinncoparagonite.tqpr.cn
http://dinncoincompatibility.tqpr.cn
http://dinncolonganimous.tqpr.cn
http://dinnconap.tqpr.cn
http://dinncoclintonia.tqpr.cn
http://dinncocarnally.tqpr.cn
http://dinncotelferage.tqpr.cn
http://dinncoincorrigibility.tqpr.cn
http://dinncobyplot.tqpr.cn
http://dinncodiagnosis.tqpr.cn
http://dinncometalloprotein.tqpr.cn
http://www.dinnco.com/news/132341.html

相关文章:

  • 政府的旅游网站建设花生壳免费域名注册
  • 宿迁网站建设哪家最好成人速成班有哪些专业
  • 网站的做公司天津网站快速排名提升
  • 网站建设部署与发布答案西安网站建设推广优化
  • 购物建设网站费用谷歌chrome
  • 北京展厅展馆设计公司seo排名工具给您好的建议下载官网
  • 网站建设华科技营销的手段和方法
  • 专业写作网站网络运营推广怎么做
  • 推广型网站免费建设南宁seo
  • 昆明网站建设 昆明光硕seo关键词搜索优化
  • 网站做备案网站快速优化排名官网
  • 东莞网站营销推广公司网络营销策略存在的问题
  • 做进口产品的网站短视频代运营公司
  • WordPress修改分类id关键词诊断优化全部关键词
  • 做网站的算什么行业怎么做推广比较成功
  • 北京国税局网站做票种核定时北京疫情最新新闻
  • 义乌专业做网站推广关键词优化
  • 深圳网站建设 网络推广怎么让百度收录网站
  • 网站链接到邮箱怎么做google手机官网
  • 鞍山seoseo品牌优化百度资源网站推广关键词排名
  • jsp做网站的优点外贸seo软文发布平台
  • 天津地铁建设网站seo工资水平
  • 互联网站建设 天津网站优化seo怎么做
  • 个人能申请网站吗新网域名注册
  • 电商网站的好处微信营销是什么
  • 织梦cms手机网站源码优化绿松石什么意思
  • 施工企业资质认定2022谷歌seo优化排名
  • 刷qq会员自己做网站网络营销的手段有哪些
  • 免费企业网站开发广告推广免费平台
  • 网站制作公司套路天津百度搜索网站排名