`
liyiting
  • 浏览: 20389 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[转] #ifdef _DEBUG用法小结

阅读更多

1
#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

 

http://blog.csdn.net/shijizhisheng/article/details/1908054

分享到:
评论

相关推荐

    #ifdef_#else_#endif_#if_#ifndef的用法.txt

    #ifdef_#else_#endif_#if_#ifndef的用法.txt

    解译#ifdef __cplusplus

    #ifdef __cplusplus } #endif 这样的代码到底是什么意思呢?首先,__cplusplus 是cpp 中的自定义宏,那么定义了这 个宏的话表示这是一段cpp 的代码,也就是说,上面的代码的含义是:如果这是一段cpp 的 代码,那么...

    #ifdef __cplusplus深度剖析

    #ifdef __cplusplus深度剖析

    预编译#define_#ifdef_#endif用法

    最近在看Linux底层代码,发现好多代码里有#define #ifdef #endif,找了个介绍详细的文章,供大家参考!

    #ifdef,#else,#endif和#ifndef的用法

    #ifdef,#else,#endif和#ifndef的用法

    linux 函数时间统计 打印

    #ifdef __TIME_TRACE_DEBUG__ # define TIME_TRACE tt::record Tt_ReCoRd_AvOiD_ReDeF(new tt::func_time_info(__func__)); # define TIME_TRACE_RESET tt::ctrl::inst()->reset(); # define TIME_TRACE_FORCE_...

    商品销售管理系统

    #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define BCMENU_GAP 1 #ifndef OBM_CHECK #define OBM_CHECK 32760 // from winuser.h #endif #if _MFC_VER ...

    超级终端程序

    #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif BEGIN_MESSAGE_MAP(CCSocketApp, CWinApp) ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ...

    debug宏合集dbg.h

    debug 宏合集 #ifdef NDEBUG #define debug(M, ...) #else #define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M ...#define check_debug(A, M, ...) if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }

    #ifdef,#else,#endif,#if用法详解

    #ifdef,#else,#endif,#if用法详解

    VC环境MP3播放器的开发附实例源代码

     #ifdef _DEBUG  #define new DEBUG_NEW  #define WM_MYMESSAGE WM_USER+6  #undef THIS_FILE  static char THIS_FILE[] = __FILE__;  #endif  修改为Release状态下的代码:  #define WM_MYMESSAGE ...

    Minix源代码

    ANSI_H 00021 #define _ANSI_H 00022 00023 #if __STDC__ == 1 00024 #define _ANSI 31459 /* compiler claims full ANSI conformance */ 00025 #endif 00026 00027 #ifdef __GNUC__ 00028 ...

    推箱子-C++课程设计(源码)

    #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif 已测试,能正常运行。 //地图状态 #define MAP_BACKGROUP 48 //'0' 对应字符'0'背景 #define MAP_WHITEWALL 49 /...

    运动会分数统计 C++

    #ifdef _MSC_VER // Currently, all MS C compilers for Win32 platforms default to 8 byte // alignment. #pragma pack(push,8) #endif // _MSC_VER #ifndef __cplusplus #error "eh.h is only for C++!" #endif ...

    stl_algobase.h

    #ifdef __STL_USE_NEW_IOSTREAMS #include #else /* __STL_USE_NEW_IOSTREAMS */ #include #endif /* __STL_USE_NEW_IOSTREAMS */ #ifndef __SGI_STL_INTERNAL_ITERATOR_H #include <stl_iterator_base.h> #...

    8192CU LINUX驱动

    //#define CONFIG_DEBUG_CFG80211 1 #endif /* * Internal General Config */ //#define CONFIG_PWRCTRL //#define CONFIG_H2CLBK #define CONFIG_EMBEDDED_FWIMG 1 //#define CONFIG_FILE_FWIMG #ifdef ...

    C++中关于Crt的内存泄漏检测的分析介绍

    代码如下:#ifdef _DEBUG#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)#else#define DEBUG_CLIENTBLOCK#endif#define _CRTDBG_MAP_ALLOC#include <crtdbg>#ifdef _DEBUG#define new DEBUG_...

    使用C语言编写圣诞表白程序

    快到圣诞节啦,男票女票都有了嘛?没有的话,有没有喜欢的女孩子或者男孩子啊?今天就给你们分享一个圣诞节的表白程序,希望你们喜欢咯,效果是这样的: ...#ifdef _DEBUG #define new DEBUG_NEW #endif // 用

    错误Amr文件修复

    #ifdef __cplusplus extern "C" { #endif /* * Class: cn_com_util_Jni * Method: convert_mp3_mehtod * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_...

    C++中基于Crt的内存泄露检测

    #ifdef _DEBUG #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) #else #define DEBUG_CLIENTBLOCK #endif #define _CRTDBG_MAP_ALLOC #include #ifdef _DEBUG #define new DEBUG_...

Global site tag (gtag.js) - Google Analytics