zoukankan      html  css  js  c++  java
  • 0042 条件编译

    /*
     
       条件编译:
     
          发生在预处理阶段,在编译之前做的事情
     
          核心:根据条件编译指定的代码
     
          条件不同,编译的部分也不同,生成的目标文件(.o)大小也不一样
     
     
     
     
     
     
     
     
     
     */
    
    
    #include <stdio.h>
    
    int main(int argc, const char * argv[]) {
       
        int score = 76;
        //判断成绩属于哪个等级
        if(score<60){
            printf("E
    ");
        }else if (score<=69){
            printf("D
    ");
        }else if (score<=79){
            printf("C
    ");
        }else if (score<=89){
            printf("B
    ");
        }else{
            printf("A
    ");
        }
        
        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
    ");
    //    }else if (score<=69){
    //        printf("D
    ");
    //    }else if (score<=79){
    //        printf("C
    ");
    //    }else if (score<=89){
    //        printf("B
    ");
    //    }else{
    //        printf("A
    ");
    //    }
        
        //    int score = 76;
        //    //判断成绩属于哪个等级
        //    if(score<60){
        //        printf("E
    ");
        //    }else if (score<=69){
        //        printf("D
    ");
        //    }else if (score<=79){
        //        printf("C
    ");
        //    }else if (score<=89){
        //        printf("B
    ");
        //    }else{
        //        printf("A
    ");
        //    }
        
        //    int score = 76;
        //    //判断成绩属于哪个等级
        //    if(score<60){
        //        printf("E
    ");
        //    }else if (score<=69){
        //        printf("D
    ");
        //    }else if (score<=79){
        //        printf("C
    ");
        //    }else if (score<=89){
        //        printf("B
    ");
        //    }else{
        //        printf("A
    ");
        //    }
        
        
        //    int score = 76;
        //    //判断成绩属于哪个等级
        //    if(score<60){
        //        printf("E
    ");
        //    }else if (score<=69){
        //        printf("D
    ");
        //    }else if (score<=79){
        //        printf("C
    ");
        //    }else if (score<=89){
        //        printf("B
    ");
        //    }else{
        //        printf("A
    ");
        //    }
        
    #if score < 60
        printf("E
    ");
    #elif score <= 69
        printf("D
    ");
    #elif score <= 79
        printf("C
    ");
    #elif score <= 89
        printf("B
    ");
    #else
        printf("A
    ");
    #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
    ",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
    ",a,b);
    
    }
    
    
    void test1(){
        
        printf("xxxxx
    ");
        float b  = 10.23f;
        Log("test1--->%.2f
    ",b);
        
    }
    
    int main(int argc, const char * argv[]) {
        
        //DEBUG1 == 1   显示调试信息
        //DEBUG1 == 0   不显示调试信息
        Log("xxxxxxxxxx-->
    ");
        
        test1();
        test();
        
        return 0;
    }
    
  • 相关阅读:
    windows server2012之部署HTTPS安全站点
    HTTPS站点搭建教程:Win7/Windows Server 2008R2
    https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题
    SQL Server中解决死锁的新方法介绍
    WCF寄宿到Windows Service[1]
    安装程序工具 (Installutil.exe)22
    安装程序工具 (Installutil.exe)
    WebSocket使用教程
    深入理解java String 对象的不可变性
    Android 给Button加个监听
  • 原文地址:https://www.cnblogs.com/aiti/p/4681771.html
Copyright © 2011-2022 走看看