zoukankan      html  css  js  c++  java
  • C标准中一些预定义的宏,如__FILE__,__func__等

    C标准中一些预定义的宏
       C标准中指定了一些预定义的宏,对于编程经常会用到。下面这个表中就是一些常常用到的预定义宏。
      宏
      意义
      __DATE__
      进行预处理的日期(“Mmm dd yyyy”形式的字符串文字)
      __FILE__
      代表当前源代码文件名的字符串文字
      __LINE__
      代表当前源代码中的行号的整数常量
      __TIME__
      源文件编译时间,格式微“hh:mm:ss”
      __func__
      当前所在函数名
      
       对于__FILE__,__LINE__,__func__这样的宏,在调试程序时是很有用的,因为你可以很容易的知道程序运行到了哪个文件的那一行,是哪个函数。
       下面一个例子是打印上面这些预定义的宏的。
    #include 
    #include 

    void why_me();

    int main()
    {
        printf( "The file is %s. ", __FILE__ );
        printf( "The date is %s. ", __DATE__ );
        printf( "The time is %s. ", __TIME__ );
        printf( "This is line %d. ", __LINE__ );
        printf( "This function is %s. ", __func__ );

        why_me();

         return 0;
    }

    void why_me()
    {
        printf( "This function is %s ", __func__ );
        printf( "The file is %s. ", __FILE__ );
        printf( "This is line %d. ", __LINE__ );
    }

    打印信息:
    The file is debug.c.
    The date is Jun  6 2012.
    The time is 09:36:28.
    This is line 15.
    This function is main.
    This function is why_me
    The file is debug.c.
    This is line 27.

  • 相关阅读:
    oracle和mysql功能相同的函数
    五个人二个月为什么不等于十个人一个月
    Oracle—RMAN完全恢复
    UVA 208 Firetruck
    sql server2005 express和Northwind数据库安装
    机器学习理论与实战(十一)关联规则分析Apriori
    JavaScript前世今生
    Maclean Liu对Oracle Database 12c新特性研究汇总
    amcharts报表制作
    HDU 4274 Spy's Work (树 DFS)
  • 原文地址:https://www.cnblogs.com/zsq1993/p/5927325.html
Copyright © 2011-2022 走看看