define的几种情况

define的两种情况:1)只是定义一个变量,不赋任何值,只是一个开关的作用。
                            2)赋予变量一个值,但是不能用等号 
                            3)赋予宏变量另一个宏,但是不能用用#if DEF_EQUAL_VALUE==10 或#if DEF_EQUAL_VALUE 来判断, 而只能 #if defined DEF_EQUAL_VALUE
              错误的情况: 用等号 会出错

// define_Macro.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

#define JUST_DEF   //just be a swith
#define DEF_VALUE 5  //can have value
//#define DEF_EQUAL=10  //will be error
//#define DEF_EQUAL_VALUE   JUST_DEF  //will be error ,because next we have #if DEF_EQUAL_VALUE==10
#define DEF_EQUAL_VALUE   DEF_VALUE
//#define DEF_EQUAL_MACRO=JUST_DEF  //be error
//#define DEF_EQUAL_MACRO  = JUST_DEF   //相当于#define DEF_EQUAL_MACRO  =
int _tmain(int argc, _TCHAR* argv[])
{
#if defined JUST_DEF
    cout<<"JUST_DEF"<<"/n";
#endif
#if DEF_VALUE==1
    cout<<"DEF_VAULE==1"<<"/n";
#else
    cout<<"DEF_VALUE!=1"<<"/n";
#endif
#if DEF_EQUAL_VALUE==10
    cout<<"DEF_EQUAL_VALUE==10"<<"/n";
#else
    cout<<"DEF_EQUAL_VALUE!=10"<<"/n";
#endif
    /*
#if DEF_EQUAL_MACRO==JUST_DEF
    cout<<"DEF_EQUAL_MACRO==JUST_DEF"<<"/n";
#else
    cout<<"DEF_EQUAL_MACRO!=JUST_DEF"<<"/n";
#endif
    */
#if defined DEF_EQUAL_MACRO
    cout<<"DEF_EQUAL_MACRO"<<"/n";
#endif
    system("pause");
    return 0;
}
未命名6

有些软件支持 =,IAR软件编译选项中加入LCD_SUPPORTED=DEBUG:
`VL5FE9WU4Z_])QXV43~{7O

在程序中可以使用判断
#if LCD_SUPPORTED==DEBUG
    #define LCD_SD  // Serial-debug
  #endif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值