如何判断代码运行在DEBUG还是RELEASE模式下
答案:1 悬赏:60 手机版
解决时间 2021-03-11 10:10
- 提问者网友:辞取
- 2021-03-10 10:32
如何判断代码运行在DEBUG还是RELEASE模式下
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-03-10 12:07
1、你是用于调试 可以用 如下宏来处理代码
1
2
3
4
5
#ifdef DEBUG
//do sth.
#else
//do sth.
#endif
2、如果是要玩花活 可以使用下面的代码,下面的代码在vc6.0中测试通过,你生成debug版,它会打印debug mode,你生成release 它会打印 release mode;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include
class is_debug{
public:
is_debug(int v) { a = v;}
int a;
};
int main()
{
unsigned this_addr;
is_debug o_o(2);
__asm mov dword ptr this_addr,eax
if ((unsigned)(&o_o)==this_addr) printf("this is debug mode!\n");
else printf("this is release mode\n");
return 0;
1
2
3
4
5
#ifdef DEBUG
//do sth.
#else
//do sth.
#endif
2、如果是要玩花活 可以使用下面的代码,下面的代码在vc6.0中测试通过,你生成debug版,它会打印debug mode,你生成release 它会打印 release mode;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include
class is_debug{
public:
is_debug(int v) { a = v;}
int a;
};
int main()
{
unsigned this_addr;
is_debug o_o(2);
__asm mov dword ptr this_addr,eax
if ((unsigned)(&o_o)==this_addr) printf("this is debug mode!\n");
else printf("this is release mode\n");
return 0;
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯