这就是#if defined 的唯一作用!

1)   #if defined XXX_XXX

#endif   是条件编译,是根据你是否定义了XXX_XXX这个宏,而使用不同的代码。

一般.h文件里最外层的

#if !defined XXX_XXX

#define XXX_XXX

#endif   是为了避免.h头文件被重复include。

2)   #error XXXX   是用来产生编译时错误信息XXXX的,一般用在预处理过程中;

例子:

#if !defined(__Dataauto)

#error C++ compiler required.

#endif

引用别人的英文用法说明:

The special operator defined is used in #if and #elif expressions to test whether a certain name is defined as a macro.

defined name and defined (name) are both expressions whose value is 1 if name is defined as a macro at the current point in the program, and 0 otherwise.

Thus, #if defined MACRO is precisely equivalent to #ifdef MACRO.   defined is useful when you wish to test more than one macro for existence at once.

For example, #if defined (__vax__) || defined (__ns16000__)  would succeed if either of the names __vax__ or __ns16000__ is defined as a macro.   Conditionals written like this: #if defined BUFSIZE && BUFSIZE >= 1024 can generally be simplified to just #if BUFSIZE >= 1024, since if BUFSIZE is not defined, it will be interpreted as having the value zero.

If the defined operator appears as a result of a macro expansion, the C standard says the behavior is undefined. GNU cpp treats it as a genuine defined operator and evaluates it normally. It will warn wherever your code uses this feature if you use the command-line option -pedantic, since other compilers may handle it differently  .

好文要顶 关注我 收藏该文  

defined 用法相关推荐

  1. python 中 del 的用法

    python 中 del 的用法 用法一 >>> a = [1, "two", 3, "four"] >>> del a[0 ...

  2. ARM 之十 ARMCC(Keil) map 文件(映射文件)详解

    在看这篇文章之前 需要对 ARM ELF 文件有一定的了解.了解什么是域(Region).节(Section,也称为节区).段(Segment).镜像(Image).镜像文件(Image File)等 ...

  3. 批处理if 命令示例详解

    本文由youxi01撰写,转载请注明. if,正如它E文中的意思,就是"如果"的意思,用来进行条件判断.翻译过来的意思就是:如果符合某一条件,便执行后面的命令. 主要用来判断,1. ...

  4. 1. 批处理常用符号详解:

    1. 批处理常用符号详解: -------------------------------------------- 1.@ 一般在它之后紧跟一条命令或一条语句,则此命令或语句本身在执行的时候不会显示 ...

  5. python之del

    由于python都是引用,而python有GC机制,所以,del语句作用在变量上,而不是数据对象上. python 中 del 的用法 用法一 >>> a = [1, "t ...

  6. bat批处理 if 命令示例详解

    if,正如它E文中的意思,就是"如果"的意思,用来进行条件判断.翻译过来的意思就是:如果符合某一条件,便执行后面的命令. if 命令示例详解 if,正如它E文中的意思,就是&quo ...

  7. #ifndef又和#if !defined()的用法一致

    #if的使用说明 #if的后面接的是表达式 #if (MAX==10)||(MAX==20)  code... #endif 它的作用是:如果(MAX==10)||(MAX==20)成立,那么编译器就 ...

  8. C语言中#if,#if defined ,#ifdef,extern的用法描述

    1.#if 和#ifdef 当asd_eee表达式存在而且,值为ture的时候接续向下执行 例如 #define TARGET_LITTLE_ENDINA 1 #define TARGET_BIG_E ...

  9. #if defined 和 #if ! defined 的用法

    背景:MFC初学,头文件中有 #if !defined(AFX_HELLOMFC_H__706D36F5_2F1B_40AC_8BE9_0BD6A1D7BBDE__INCLUDED_) #define ...

  10. 条件编译#define、#undef、#if、#elif、#elif defined、#elif !defined 、#endif用法

    条件编译 上代码 // what is the fucking shit.cpp : 定义控制台应用程序的入口点. //#include "stdafx.h"#include &l ...

最新文章

  1. 在MyEclipse中导入做好的java项目出现错误The project cannot be built until build path errors are resolved
  2. Java File类应用:递归遍历文件夹和递归删除文件
  3. AtCoder AGC029E Wandering TKHS
  4. python大神作品_掌握了这24个顶级Python库,你就是大神!
  5. fullcalendar5.X版本 显示自定义html内容
  6. JAVA 技术类分享(一)
  7. 深入ASP.NET MVC之七:ActionResult的执行(View的加载和渲染)
  8. GDataDate 的本地时间转换
  9. 什么是类?什么是对象?类与对象之间是什么关系?类的特性有哪些?
  10. 运行 Android 的笔记本 Cosmo 已众筹超 130 万美元
  11. 458、Java框架112 -【MyBatis - 一级缓存、二级缓存】 2020.12.28
  12. 手机百度打不开html网页,手机百度为什么打不开网页 网页打不开解决方法
  13. V380固件自动升级失败修复过程
  14. 深度技术 GHOST XP SP3 快速装机专业版 V2012.03
  15. 《乌合之众》60条基本观点
  16. 增加ATMEGA328 实验电路板对外引脚
  17. 物联网的发展前景怎么样?
  18. matlab实现三自由度机械臂旋转
  19. 数据分析的前世今生_李孟_新浪博客
  20. 3DMAXDragonBones中骨骼绑定,IK约束,蒙皮权重的概念

热门文章

  1. 12级计算机动画制作专业,计算机专业技术12级是什么意思?
  2. 富贵论坛的来历和背景
  3. 2019计算机世界语言排名,2019程序语言排行_2019 年 8 月编程语言排行榜
  4. 【转】浏览器中的data类型的Url格式,data:image/png,data:image/jpeg!
  5. 计算机硬件输出设备有哪些,输出设备有哪些,输出设备的作用
  6. OpenNLP 自然语言处理工具
  7. 帮助睡眠最好的办法是什么?对睡眠好的东西分享
  8. 如何设置父层DIV不动子层DIIV透明且随滚动条晃动或是不晃动
  9. 美化Hexo 个人博客
  10. 句子迷,语录,苏引华