#ifdef-#endif的作用及其使用技巧
|
1
2
3
|
#ifdef语句1//程序2#endif |
|
1
2
3
4
5
6
7
8
9
|
#include<iostream>usingnamespacestd;intmain(intargc,char*argv[]){#ifdefDEBUGcout<<"Beginningexecutionofmain()"<<endl;#endifreturn0;} |
|
1
|
Pressanykeytocontinue |
|
1
2
3
4
5
6
7
8
9
10
|
#include<iostream>usingnamespacestd;#defineDEBUGintmain(intargc,char*argv[]){#ifdefDEBUGcout<<"Beginningexecutionofmain()"<<endl;#endifreturn0;} |
|
1
2
|
Beginningexecutionofmain()Pressanykeytocontinue |
|
1
2
3
|
#defineDEBUG#ifdefDEBUG#endif |
|
1
2
3
4
5
6
7
8
9
|
#include<iostream>#include"head.h"intmain(intargc,char*argv[]){#ifdefDEBUGcout<<"Beginningexecutionofmain()"<<endl;#endifreturn0;} |
|
1
2
|
Beginningexecutionofmain()Pressanykeytocontinue |
|
1
2
3
4
5
|
#ifdef标识符//程序段1#else//程序段2#endif |
|
1
2
3
|
#ifdef标识符//程序段1#endif |
|
1
2
3
4
5
|
#ifdefWINDOWS#defineMYTYPElong#else#defineMYTYPEfloat#endif |
|
1
|
#defineWINDOWS |
|
1
|
#defineMYTYPElong |
|
1
|
#define |
|
1
2
3
|
#ifdefDEBUGprint("device_open(%p)\n",file);#endif |
|
1
|
#defineDEBUG |
DEBUG”命令即可,这时所有的用DEBUG作标识符的条件编译段都使其中的printf语句不起作用,即起统一控制的作用,如同一个“开关”一样。
|
1
2
3
4
5
|
#ifndef标识符//程序段1#else//程序段2#endif |
|
1
2
3
4
5
|
#if表达式//程序段1#else//程序段2#endif |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#defineLETTER1intmain(intargc,char*argv[]){charstr[20]="CLanguage";charc;inti=0;while((c=str[i])!='\0'){i++;#ifLETTERif(c>='a'&&c<='z')c=c-32;#elseif(c>='A'&&c<='Z')c=c+32;#endifprintf("%c",c);}return0;} |
|
1
|
CLANGUAGE |
|
1
|
#defineLETTER0 |
|
1
|
clanguage |
#ifdef-#endif的作用及其使用技巧的更多相关文章
- “#if 0/#if 1 ... #endif”的作用
1. "#if 0/#if 1 ... #endif"的作用,我们知道,C标准不提供C++里的"//"这样的单行风格注释而只提供"/* */" ...
- 头文件里面的ifndef /define/endif的作用
c,c++里面,头文件里面的ifndef /define/endif的作用 今天和宿舍同学讨论一个小程序,发现有点地方不大懂······ 是关于头文件里面的一些地方: 例如:要编写头文件test.h ...
- c语言中“#if 0 / #if 1 ... #endif”的作用
原帖地址:http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=2028608&bbs_page_no=1005&bbs_id=9999 1. ...
- #ifdef __cplusplus extern c #endif 的作用
#ifdef __cplusplus // C++编译环境中才会定义__cplusplus (plus就是"+"的意思) extern "C" { // 告诉编 ...
- 转:C++中 #ifdef 和#endif的作用
一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部分内容指定编译的条件,这就是"条件编译".有时,希望当满足某条件时对一组 ...
- C语言中#ifdef,#ifndef和#endif的作用
现在规定一下头文件书写规范, 根据陈皓编写的跟我一起些makefile,一定要记住:头文件中应该只是声明,而定义应该放在C/C++文件中.否则如果出现有定义,比如头文件中有int a =2;如果有多个 ...
- ifndef/define/endif 和 #ifdef 、#if 作用和用法
为了能简单的看看某些linux内核源码,复习了一下c语音,今天汇总了一下关于宏定义的相关内容: 一.ifndef/define/endif用法: .h文件,如下: #ifndef XX_H #defi ...
- C++中 #ifdef 和#endif的作用
一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部分内容指定编译的条件,这就是"条件编译".有时,希望当满足某条件时对一组 ...
- #ifdef _DEBUG/ #define new DEBUG_NEW/ #endif的作用
转载:https://blog.csdn.net/minghui_/article/details/80748142 转自:#ifdef _DEBUG #define new DEBUG_NEW #e ...
- ifndef/define/endif 的作用
转载自百度百科 ,感谢度娘 1 2 3 #ifdef语句1 //程序2 #endif 可翻译为:如果宏定义了语句1则执行程序2. 作用:我们可以用它区隔一些与特定头文件.程序库和其他文件版本有关的代码 ...
随机推荐
- git入门篇-----本地操作
一 ,git的简介 1 ,git的历史 概念性的知识,大家百度一下,就会出现好多优秀的文章供参考,这里我就不多说了. 如果不是当年BitMover公司威胁Linux社区,可能现在我们就没有免费而超级好 ...
- RedisTemplate操作Redis
RedisTemplate Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有序 ...
- [原创]Scala学习:流程控制,异常处理
1.流程控制 1)do..while def doWhile(){ var line="" do{ line = readLine() println("readline ...
- 【leetcode刷题笔记】Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 全屏滚动插件之 fullpage.js
前言:做移动端网页下滑/点击切换到下一页的效果,采用了fullpage,js最新的版本 https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.0.4 ...
- 95th percentile concentration
很多网络流量监控软件都提供了一个95th的值,开始一直不太理解,终于在solarwinds官网找到答案. 95th百分点指的是所给数集中超过其95%的数.它是一个统计学上的概念.对于某个接口,准确统计 ...
- linux bash缓存
http://www.xuebuyuan.com/296675.html 在已经运行的系统中更改了某些以前存在于PATH环境变量所指明的目录中的程序的存放目录后可能出现No such file or ...
- Spring Cloud之Feign客户端超时时间配置
关于雪崩效应: 默认情况下tomcat只有一个线程去处理客户端发送的所有请求.高并发情况下,如果客户端请求都在同一接口,tomcat的所有线程池去处理,导致其他接口服务访问不了,等待. Tomcat有 ...
- tp导出excel
//数据导出 protected function dao($db,$where,$join,$field){ $data = M($db)->join($join)->where($wh ...
- shell 中 exec 和 source 命令解析
文章大部分来源于:http://www.cnblogs.com/zhaoyl/archive/2012/07/07/2580749.html 作为笔记留存博客备忘. exec和source都属于bas ...