#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. 作用:我们可以用它区隔一些与特定头文件.程序库和其他文件版本有关的代码 ...
随机推荐
- oracle游标用法
-- 声明游标:CURSOR cursor_name IS select_statement --For 循环游标 --(1)定义游标 --(2)定义游标变量 --(3)使用for循环来使用这个游标 ...
- jquery链式语法
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- Spring MVC 通过反射将数据导出到excel
直接上代码 // 导出excel方法 @RequestMapping("exportExcel") public void exportExcel(HttpServletReque ...
- form表单验证失败,阻止表单提交
form表单验证失败,阻止表单提交 效果演示: 贴上完整代码: <!DOCTYPE html> <html lang="en"> <head> ...
- jquery的ajax(err)
load()方法 load()方法是jquery中最为简单和常用的ajax方法. 直接使用ajax技术的流程 1.创建xmlhttprequest对象 2.调用open函数("提交方式&qu ...
- asp.net中关于《%=》《%#》《%》 的用法——(转帖)
1:在.aspx页面,<% %>标签相当于在.cs页面的代码,也就是说你在.cs文件里面怎样写,就可以在.aspx文件里面的<% %>标签里面怎样写. 2:在.aspx页面,& ...
- ES提高数据压缩的设置——单字段,去掉source和all
curl -XPUT 'http://localhost:9200/hec_test3' -d ' { "mappings": { "hec_type3": { ...
- 大数据日志分析产品——SaaS Cloud, e.g. Papertrail, Loggly, Sumo Logic;Open Source Frameworks, e.g. ELK stack, Graylog;Enterprise Products, e.g. TIBCO LogLogic, IBM QRadar, Splunk
Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brough ...
- JavaWEB - 静态include指令、动态Include指令
(一)使用静态include指令 <%@ page language="java" contentType="text/html; charset=gb2312&q ...
- FFmpeg 的sws_getContext函数 、sws_scale函数
FFmpeg里面的sws_scale库可以在一个函数里面同时实现:1.图像色彩空间转换:2.分辨率缩放:3.前后图像滤波处理. 其核心函数主要有三个: // 初始化sws_scalestruct Sw ...