zoukankan      html  css  js  c++  java
  • __FILE__ __LINE__ C++ 宏定义 调试

    参考博文:http://www.cnblogs.com/lixiaohui-ambition/archive/2012/08/21/2649052.html

    自定义宏定义,来控制printf输出调试信息。

      1)使用可变参数的宏  ##__VA_ARGS__  来对应printf的多参数。(注意:其中 __  为2个连续的”_“)

      2) 使用编译器内置的宏  __FILE__    __LINE__ 来输出代码所在文件名及行号(注意:其中 __  为2个连续的”_“)

    代码示例如下:

    //================================================
    // Name : debug.cpp
    // Author : vin
    // Version : 1.0
    // Description : Hello World in C++, Ansi-style
    //================================================
    
    #include <stdio.h>
    #include <stdlib.h>
    #define _DEBUG_
    #ifdef _DEBUG_
        #define DEBUG(format, ...)  printf("File: " __FILE__ ", Line: %05d:" format "\n", __LINE__,##__VA_ARGS__)
    #else
        #define DEBUG(format, ...)
    #endif
     
    int main()
    {
        char str[] = "Hello World";
        DEBUG("A ha,check me :%s", str);
       // printf("hello\n");
        system("pause");
        return 0;
    }

    在代码调试阶段,保留 ”#define _DEBUG_“;在发布时,直接注释掉该宏,则不会输出调试信息,非常方便。

  • 相关阅读:
    关于git status
    JS的trim()方法
    js自定义方法名
    Autoit3 如何捕足控件
    AutoIt 脚本1
    Python2和Python3语法区别
    使用jmeter测试数据库性能
    selenium-Python之上传文件
    selenium-Python之鼠标事件
    selenium-Python之鼠标事件
  • 原文地址:https://www.cnblogs.com/wenshanzh/p/2982151.html
Copyright © 2011-2022 走看看