参考地址:http://www.cnblogs.com/ezrax/archive/2008/08/06/1262032.html
在看例程的时候,经常看到主函数开始前会有这样的代码,知道是用作调试的。但对此比较模糊,
int main(void)
{
#ifdef DEBUG
debug();
#endif
在工程设置里有一些设置会对该工程自动产生一系列的宏,用以控制程序的编译和运行。如果你把代码夹在#ifdef DEBUG 和对应的 #endif 中间,那么这段代码只有在调试(DEBUG)下才会被编译。也就是说,如果你在RELEASE模式下,这些代码根本就不会存在于你的最终代码里头。
你可以手动实现DEBUG的定义如:
#define DEBUG
这些宏代码本身是面向编译器使用的,不要用来实现你的业务逻辑代码,这样会带来很不好的影响。这类宏定义的一个典型应用就是产生/屏蔽调试信息,看下面的例子
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--> 1 #include <iostream>
2 using namespace std;
3
4 #ifdef DEBUG
5 inline void msg(){ cout<<"I'm testing"; }
6 #else
7 inline void msg() {}
8 #endif
9
10 int main()
11 {
12 msg();
13
14 return 0;
15 }
上面的代码在DEBUG 模式下是会输出一句话的,你可以把这种应用放在你希望对程序的执行过程进行跟踪的代码里,为它们加上一些‘痕迹’,方便你进行判断。而在其他模式(RELEASE)下,这个函数只不过是一个空函数,又因为它是inline的,所以它实际上不会为你产生任何代码。这样你就能为自己的代码带来一种非常实用的效果,既能在DEBUG模式下为你提供判断的依据,又能在最终的RELEASE版中方便的抛弃掉它们,而不需要你手动地删除掉那些代码。
作为宏指令,如果定义了DEBUG宏那么编译#IF后面到#ENDIF的代码否则不编译DEBUG宏一般是编译器产生,如果编译模式是DEBUG就会产生这个宏,如果是RELEASE就不会
分享到:
相关推荐
#ifdef DEBUG #import "TXFPSCalculator.h" #endif STEP 2: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window makeKeyAndVisible...
#ifdef DEBUG debug(); #endif /*Core initialization*/ /*NVIC first,before RCC initialization,use HSI,because RCC initialization also may have INT,GPIO last*/ NVIC_Configuration(); RCC_...
#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_...
代码如下:#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_...
#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 #pragma comment(lib,"libcurld.lib") #else #pragma comment(lib,"libcurl.lib") #endif #pragma comment ( lib, "ws2_32.lib" ) #pragma comment ( lib, "winmm.lib" ) #pragma comment ( lib, ...
//#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 ...
#ifdef DEBUG debug(); #endif /* System Clocks Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO ports pins Configuration */ GPIO_Configuration(); USART_...
#ifdef _DEBUG #ifndef _WIN64 #pragma comment(lib, "zlog_vc100x86.debug.lib") #else #pragma comment(lib, "zlog_vc100x64.debug.lib") #endif #else #ifndef _WIN64 #pragma comment(lib, "zlog_vc100x86....
#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() ...
#ifdef DEBUG debug(); #endif System_Configuration(); printf("This is an example of PID!\n\r"); while (1) { switch (N){ case 0: if(Flag_1mS==1){ if(U_Set-ADCConvertedValue>=10||U_Set-...
快到圣诞节啦,男票女票都有了嘛?没有的话,有没有喜欢的女孩子或者男孩子啊?今天就给你们分享一个圣诞节的表白程序,希望你们喜欢咯,效果是这样的: ...#ifdef _DEBUG #define new DEBUG_NEW #endif // 用
#ifndef __TIME_TRACE_UTILS__ #define __TIME_TRACE_UTILS__ #include #include #include #include #include #include #include #include ...#define NS_TT_START namespace tt...#endif // __TIME_TRACE_DEBUG__
#ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; ...
#ifdef DEBUG debug(); #endif //配置系统时钟 sys_config(); //配置 NVIC 和 Vector Table NVIC_Configuration(); //配置使用的GPIO口 GPIO_Configuration(); //改变指定管脚的映射 GPIO_Remap_SWJ_...
#ifdef DEBUG // 1. 默认位置开启 FPS 监听,可拖动 [[AYYFPSIndicator sharedInstance] start]; #endif return YES; } 2. statusBar 显示 FPS值 - (BOOL)application:(UIApplication *)application ...
#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 ...
#ifdef NDEBUG #define debug(M, ...) #else #define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) //牛逼 #endif #define clean_errno() (errno == 0 ? "None" : ...
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CHTTPClientApp
#ifdef _DEBUG #pragma comment(lib, "./lib/hiredisd.lib") #else #pragma comment(lib, "./lib/hiredis.lib") #endif #pragma warning(pop) // 恢复4200警告 更多问题可以到我的blog上留言