#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE

#ifdef _DEBUG #define new DEBUG_NEW #endif 用vs2012的编译器根据向导生成的代码,里面都会出现 #ifdef _DEBUG #define new DEBUG_NEW #endif 这个的详细解释是什么呢,查看msdn解释如下: 在寻找内存泄漏的帮助。 在调试模式 (在 _DEBUG 符号定义) 时, DEBUG_NEW 记录其分配的每个对象的文件名和行号。 然后,那么,当您使用 CMemoryState:: 阅读详情


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE


在debug8版本(调试版本),就将new(申请内存)的操作符改成DEBUG_NEW,估计会抛异常等带调试手段的函数

取消THIS_FILE这个宏的定义
DEBUG_NEW 
#define new DEBUG_NEW 
说明: 
帮助查找内存错误。用户在程序中使用DEBUG_NEW,用户通常使用new运算符来从堆上分配。在Debug模式下(但定义了一个DEBUG符号),DEBUG_NEW为它分配的每个对象记录文件名和行号。然后,在用户使用CMemoryState::DumpAllObjectSince成员函数时,每个以DEBUG_NEW分配的对象分配的地方显示出文件名和行号。 为了使用DEBUG_NEW,应在用户的资源文件中插入以下指令: #define new DEBUG_NEW 一旦用户插入本指令,预处理程序将在使用new的地方插入DEBUG_NEW,而MFC作其余的工作。但用户编译自己的程序的一个发行版时,DEBUG_NEW便进行简单的new操作,而且不产生文件名和行号消息。 

#ifdef _DEBUG //如果定义了_DEBUG,也就是调试版程序,则执行以下三句 
#define new DEBUG_NEW //定义new为DEBUG_NEW 
#undef THIS_FILE //取消以前对THIS_FILE的定义 
static char THIS_FILE[] = __FILE__; //声明并初始化THIS_FILEO数组,数据的初始数据为该文件的文件名 
#endif 

__FILE__ 就是当前源文件的名称

#undef THIS_FILE的问题 MFC给你生成的cpp文件里面都有这么几行:   1  #ifdef _DEBUG   2  #define new DEBUG_NEW   3  #undef THIS_FILE   4  static char THIS_FILE[] = __FILE__;   5   #endif 在Visual studio 中通常只用1~3行。对于这段代码的作用,通常有一下解释: 阅读详情

相关推荐

动态链接库(MFC动态链接库)的建立与使用

至此,Debug与Release文件夹下生成的make_Dynamic_Link_Library.dll便可供外部使用。

陆先森不怕鬼的博客 1966

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

VS2010环境下,添加MFC Class时,程序会自动生成框架代码,cpp文件的include下面有如下语句: #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif以下是这段代码的相关解释: #ifdef _DEBUG //如果定义了_DEBUG

天道酬勤 3311

vc++ADOX创建数据库

vc++利用ADOX创建数据库 // ADOXCreateDatabaseDlg.cpp : implementation file // #include "stdafx.h" #include "ADOXCreateDatabase.h" #include "ADOXCreateDatabaseDlg.h" #include "Shlwapi.h" #pragma comment(lib,"shlwapi.lib") // Download by http://www.codefans.net #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CADOXCreateDatabaseDlg dialog CADOXCreateDatabaseDlg::CADOXCreateDatabaseDlg(CWnd* pParent /*=NULL*/) : CDialog(CADOXCreateDatabaseDlg::IDD, pParent) { //{{AFX_DATA_INIT(CADOXCreateDatabaseDlg) m_dbName = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CADOXCreateDatabaseDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CADOXCreateDatabaseDlg) DDX_Text(pDX, IDC_DBNAME, m_dbName); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CADOXCreateDatabaseDlg, CDialog) //{{AFX_MSG_MAP(CADOXCreateDatabaseDlg) ON_WM_SYSCOMM

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

情况1: #ifdef _DEBUG virtual void AssertValid() const; //assert(断言)valid(有效的,正确的) virtual void Dump(CDumpContext& dc) const; //存储上下文 #endif 这两个函数是调试用的,第一个函数检查可用性,即是否有效。第二个函数如果未更

qing666888的专栏 919

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

在用vc时,利用AppWizard会产生如下代码: #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif对于 #define new DEBUG_NEW 首先看msdn的解释: 再查看定义: #ifdef _DEBUG void* AFX_CD

小凡的专栏 1万+

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

这段代码在 MFC 的调试版本中起着重要的作用,主要是为了在内存分配时能够记录更多的调试信息,以便在后续的调试过程中能够有效地发现和定位内存泄漏等问题,从而提高程序的稳定性和可靠性。

weixin_36672036的博客 236

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

<br />情况1:<br />#ifdef _DEBUG<br />virtual void AssertValid() const;                                       //assert(断言)valid(有效的,正确的)<br />virtual void Dump(CDumpContext& dc) const;            //存储上下文<br />#endif<br />这两个函数是调试用的,第一个函数检查可用性,即是否有效<br />第二个函数

panjean的专栏 2548

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

情况1:#ifdef _DEBUGvirtual void AssertValid() const;                                       //assert(断言)valid(有效的,正确的)virtual void Dump(CDumpContext& dc) const;            //存储上下文#endif这两个函数是调试用的,第一个函数

Beyond.cn 5277

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

#ifdef _DEBUG //如果_DEBUG已定义 #undef THIS_FILE //取消定义THIS_FILE static char THIS_FILE[]=__FILE__;//定义THIS_FILE,把当前的文件名存入THIS_FILE#define new DEBUG_NEW //定义DEBUG_NEW #endif

NCTU_to_prove_safety的博客 563

#ifdef _DEBUG的意思

#ifdef _DEBUG //如果_DEBUG已定义 #undef THIS_FILE //取消定义THIS_FILE static char THIS_FILE[]=__FILE__;//定义THIS_FILE,把当前的文件名存入THIS_FILE#define new DEBUG_NEW //定义DEBUG_NEW #endif

东方猫的博客 699

DEBUG_NEW未定义错误

转载地址 :点击打开链接 拿别人的代码过来用,编译的时候出现如下错误 error: identifier "DEBUG_NEW" is undefined 找了google和百度没有解决办法,后来发现是这几行代码搞鬼 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FIL

scutedu的博客 2688

#define

C语言中#undef的语法是: #undef 标识符 用来将前面定义的宏标识符取消定义。 整理了如下几种常见用法,如果以后发现其他的再添加进来。 1、在一个程序块中用完宏定义后,为防止后面标识符冲突需要取消其宏定义: #include int main() { #define MAX 200 printf("MAX = %d\n", MA

splityyj的博客 468

__FILE__的含义

__FILE__为预编译器常量,返回当前编译的文件名,还有比较常用的几个预编译器常量,     __LINE__编译器在编译的文件的第几行;     __DATE__返回当前的日期Jul-20-2004;     __TIME__返回当前的时间hh:mm:ss;         如下为宏定义:     #ifdef   _DEBUG     //如果定义了_DEBUG     #define  

yinxusen的专栏 910

C基础笔记20250325

define由于宏仅是文本替换,在调试时查看变量值时无法直接看到宏的名字,这可能使调试更加困难。宏的作用范围从定义点开始直到文件结束或遇到#undef指令为止,不具备块级作用域的概念。宏是全局性的,除非特别限制在一个文件内通过条件编译实现。适合用于定义简单的常数值,特别是当这个值需要被用作数组大小、case标签或其他不允许有变量的地方。也常用于条件编译。const。

qq_33552379的博客 988
上一篇: USCAO section 4.1 Fence Loops(最短路,最小环,5级)
下一篇: UVA 11478 Halum(差分约束,5级)
剑不飞
博客等级 码龄15年 85粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值