0042 条件编译
2015-07-28 08:46
232 查看
/* 条件编译: 发生在预处理阶段,在编译之前做的事情 核心:根据条件编译指定的代码 条件不同,编译的部分也不同,生成的目标文件(.o)大小也不一样 */ #include <stdio.h> int main(int argc, const char * argv[]) { int score = 76; //判断成绩属于哪个等级 if(score<60){ printf("E\n"); }else if (score<=69){ printf("D\n"); }else if (score<=79){ printf("C\n"); }else if (score<=89){ printf("B\n"); }else{ printf("A\n"); } return 0; }
// // main.c // 20-#if-#else 条件编译指令 // // Created by apple on 15/1/11. // Copyright (c) 2015年 itcast. All rights reserved. // #include <stdio.h> #define score 99 int main(int argc, const char * argv[]) { //传统方式 // int score = 76; // //判断成绩属于哪个等级 // if(score<60){ // printf("E\n"); // }else if (score<=69){ // printf("D\n"); // }else if (score<=79){ // printf("C\n"); // }else if (score<=89){ // printf("B\n"); // }else{ // printf("A\n"); // } // int score = 76; // //判断成绩属于哪个等级 // if(score<60){ // printf("E\n"); // }else if (score<=69){ // printf("D\n"); // }else if (score<=79){ // printf("C\n"); // }else if (score<=89){ // printf("B\n"); // }else{ // printf("A\n"); // } // int score = 76; // //判断成绩属于哪个等级 // if(score<60){ // printf("E\n"); // }else if (score<=69){ // printf("D\n"); // }else if (score<=79){ // printf("C\n"); // }else if (score<=89){ // printf("B\n"); // }else{ // printf("A\n"); // } // int score = 76; // //判断成绩属于哪个等级 // if(score<60){ // printf("E\n"); // }else if (score<=69){ // printf("D\n"); // }else if (score<=79){ // printf("C\n"); // }else if (score<=89){ // printf("B\n"); // }else{ // printf("A\n"); // } #if score < 60 printf("E\n"); #elif score <= 69 printf("D\n"); #elif score <= 79 printf("C\n"); #elif score <= 89 printf("B\n"); #else printf("A\n"); #endif return 0; }
/* 条件编译指令 1) #if #elif #else #endif 2) #ifdef 用来判断某个宏是否定义 */ #include <stdio.h> #define DEBUG1 1 #define DEBUG2 0 int main(int argc, const char * argv[]) { int a = 0; //ifdef检测宏是否定义 #ifdef DEBUG1 //DEBUG 系统已经定义了这个宏了 a = 10; #else a = 10000; #endif //ifndef 检测宏是否定义 ifndef 如果没有定义 #ifndef DEBUG2 a = 100; #else a = -1; #endif printf("%d\n",a); return 0; }
// // main.c // 22-使用条件编译指令调试bug // // Created by apple on 15/1/11. // Copyright (c) 2015年 itcast. All rights reserved. // #include <stdio.h> #define DEBUG1 1 #if DEBUG1 == 1 //显示调试信息 #define Log(format,...) printf(format,## __VA_ARGS__) #else //不显示调试信息 #define Log(format,...) #endif void test(){ int a = 10,b=3; Log("test--->%d,%d\n",a,b); } void test1(){ printf("xxxxx\n"); float b = 10.23f; Log("test1--->%.2f\n",b); } int main(int argc, const char * argv[]) { //DEBUG1 == 1 显示调试信息 //DEBUG1 == 0 不显示调试信息 Log("xxxxxxxxxx-->\n"); test1(); test(); return 0; }
相关文章推荐
- JavaScript 开发规范
- UML建模 步骤
- [BZOJ1664] [Usaco2006 Open]County Fair Events 参加节日庆祝
- It's not a Bug, It's a Feature! (poj 1482 最短路SPFA+隐式图+位运算)
- WHU 1551 Pairs(分块暴力)
- JavaScript-2015.7.27
- Verilog HDL语言不全面但基本入门够用介绍
- 极客头条---人人都是主编(上)
- poj-2965 The Pilots Brothers' refrigerator -- 枚举
- 第三周第一天(【正则表达式的应用】【卖票问题】【同一个账号两人同时取钱】【生产消费问题】【join】【死锁问题】)
- 如此理解面向对象编程
- 极客头条---人人都是主编(上)
- 容器时代,难道这就是我们想要的未来?
- Calculation 2-欧拉函数的运用
- UVA 442 Matrix Chain Multiplication
- C++使用libcurl做HttpClient
- 安卓手机来电亮屏流程分析
- 计算机视觉目标检测的框架与过程(转)
- leetcode 240: Search a 2D Matrix II C++Version
- Javascript高级程序设计