#ifdef _DEBUG virtual void AssertValid() const; //assert(断言)valid(有效的,正确的) virtual void Dump(CDumpContext& dc) const; //存储上下文 #endif 这两个函数是调试用的,第一个函数检查可用性,即是否有效 第二个函数如果未更改的话,最终调用的是Cwnd::Dump(); 输出窗口类名,标题名等一系列信息(在输出窗口中) #ifdef _DEBUG #endif 这是条件编译,即如果有#define _DEBUG这两个函数会编译,否则忽略, 当你用debug生成时(相对于release)开发环境则自动的加上这个宏定义,这两个函数有效。

2 #ifdef   _DEBUG     //   判断是否定义_DEBUG   #undef   THIS_FILE     //   取消THIS_FILE的定义   static   char   THIS_FILE[]=__FILE__;     //   定义THIS_FILE指向文件名   #define new    DEBUG_NEW     //   定义调试new宏,取代new关键字   #endif     //   结束       如果定义了_DEBUG,表示在调试状态下编译,因此相应修改了两个符号的定义 THIS_FILE是一个char数组全局变量,字符串值为当前文件的全路径,这样在Debug版本中当程序出错时出错处理代码可用这个变量告诉你是哪个文件中的代码有问题。 定义 _DEBUG后,由于定义了_DEBUG,编译器确定这是一个调试,编译#ifdef   _DEBUG和#endif之间的代码。#undef   表示清除当前定义的宏,使得THIS_FILE无定义。__FILE__   是编译器能识别的事先定义的ANSI   C   的6个宏之一。#define   new   DEBUG_NEW   DEBUG_NEW定位内存泄露并且跟踪文件名. //////////////////////////////////////////////////////////////////////// ///另一种解释 #ifdef     _DEBUG     //如果是debug状态   #undef     THIS_FILE     //清除THIS_FILE   static     char     THIS_FILE[]=__FILE__;     //定义THIS_FILE为                                        //__FILE__(这是当前文件全路径名字)       #define    new     DEBUG_NEW     //定义new为DEBUG_NEW(这个可以检测到内存泄露之类的问题,其实就是可以使用crt开头的那几个调试函数)   #endif

在用vc时,利用AppWizard会产生如下代码:

#ifdef _DEBUG  #define new DEBUG_NEW  #undef THIS_FILE  static char THIS_FILE[] = __FILE__;  #endif

对于

#define new DEBUG_NEW 首先看msdn的解释:

Assists in finding memory leaks. You can use DEBUG_NEW everywhere in your program that you would ordinarily use the new operator to allocate heap storage.

In debug mode (when the _DEBUG symbol is defined), DEBUG_NEW keeps track of the filename and line number for each object that it allocates. Then, when you use the CMemoryState::DumpAllObjectsSince member function, each object allocated with DEBUG_NEW is shown with the filename and line number where it was allocated.

To use DEBUG_NEW, insert the following directive into your source files:

#define new DEBUG_NEW

Once you insert this directive, the preprocessor will insert DEBUG_NEW wherever you use new, and MFC does the rest. When you compile a release version of your program, DEBUG_NEW resolves to a simple new operation, and the filename and line number information is not generated.

再查看定义:

#ifdef _DEBUG

void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);           #define DEBUG_NEW new(THIS_FILE, __LINE__)

#else

#define DEBUG_NEW new

#endif

#ifdef _DEBUG的更多相关文章

  1. #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #endif

    情况1:#ifdef _DEBUGvirtual void AssertValid() const;                 //assert(断言)valid(有效的,正确的)virtual ...

  2. 【转】#ifdef _DEBUG用法小结

    原文地址:http://blog.csdn.net/shijizhisheng/article/details/1908054 1 #ifdef _DEBUG virtual void AssertV ...

  3. #ifdef _DEBUG/ #define new DEBUG_NEW/ #endif的作用

    转载:https://blog.csdn.net/minghui_/article/details/80748142 转自:#ifdef _DEBUG #define new DEBUG_NEW #e ...

  4. #ifdef _DEBUG #define new DEBUG_NEW #endif的解释

    转载:https://blog.csdn.net/sinat_20265495/article/details/51762738 在用vc时,利用AppWizard会产生如下代码:#ifdef _DE ...

  5. 气死人不偿命,Q_OBJECT导致的C++报错,而且还看不明白(#ifdef没控制好,导致什么都不认识了)

    为了代码可以同时适应VC++和MingW编译器,我改动了我的代码,变成: #ifdef _MSC_VER #pragma comment(lib, "crypt32.lib") / ...

  6. 预编译指令#ifdef #endif

    这个是C中的.意思是说如果你定义了某个东西,则执行一段代码,这段代码是包含在ifdef到endif之间的.比如,你debug一个程序,但是到最后你需要将debug的代码删掉,很多则很麻烦.但是如果你那 ...

  7. ifdef等宏的妙用

    条件编译 一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部分内容指定编译的条件,这就是"条件编译". 条件编译命令最常见 ...

  8. CoreCLR源码探索(一) Object是什么

    .Net程序员们每天都在和Object在打交道 如果你问一个.Net程序员什么是Object,他可能会信誓旦旦的告诉你"Object还不简单吗,就是所有类型的基类" 这个答案是对的 ...

  9. OpenCV人脸识别Eigen算法源码分析

    1 理论基础 学习Eigen人脸识别算法需要了解一下它用到的几个理论基础,现总结如下: 1.1 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...

随机推荐

  1. 解决 Xamarin 拖拽Plain Text 于Layout上时 出现 “The layout could not be loaded:java.lang.System.arraycopy([CI[CII)V” 错误

    右键项目属性

  2. [转] asp.net <%%>&<%#%>&<%=%>&<%@%>&<%$%>用法区别

    转自  参考 1.<% %>用来绑定后台代码 如: < % for(int i=0;i<100;i++) { Reaponse.Write(i.ToString()); } % ...

  3. ofbiz进击 。 ofbiz 退货流程(包含获取可退货项流程分析 以及 取消退货项的过程分析)

    根据订单获取可退货项流程分析 退货的时候,调用 services_return.xml 中的获取可进行退货的退货项  getReturnableItems  ,该服务调用了Java类 org.ofbi ...

  4. 在EditText前面添加一个搜索的小图片

    1,这是EditText中的一个小的属性 代码: android:drawableLeft="@drawable/searchico" 效果图如下:

  5. java中创建线程的几种方法及区别

    1,实现Runnable接口创建线程 特点: A:将代码和数据分开,形成清晰的模型 B:线程体run()方法所在的类可以从其它类中继承一些有用的属性和方法 C:有利于保持程序风格的一致性 2,继承Th ...

  6. 夺命雷公狗—angularjs—8—ng-class的简单用法

    我们在正常的业务处理中往往会遇到一些逻辑类的问题,比如各行换色,现在angularjs里面也给我们提供了一个小小的的class处理的方式,废话不多说,如下所示: <!doctype html&g ...

  7. 【ubuntu】首选项和应用程序命令(preference & application)

     gnome-control-center  系统设置  gnome-control-center region  键盘布局  gnome-control-center screen  屏幕  gno ...

  8. 【py技巧】使用reload重导入修改过的包或模块

    #使用import导入 import my_module my_module.something() #out - orignal #这里修改输出 - changed reload(my_module ...

  9. SQL Server安装完成后3个需要立即修改的配置选项(转载)

    你用安装向导安装了全新的SQL Server,最后你点击了完成按钮.哇噢~~~现在我们可以把我们的服务器进入生产了!抱歉,那并不是真的,因为你的全新SQL Server默认配置是错误的. 是的,你没看 ...

  10. SQL删除重复数据方法

    例如: id           name         value 1               a                 pp 2               a           ...