博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C语言宏
阅读量:4230 次
发布时间:2019-05-26

本文共 601 字,大约阅读时间需要 2 分钟。

ANSI C标准中有几个标准预定义宏:__FILE__     __DATE__   __TIME___    __LINE__   等

__LINE__:在源代码中插入当前源代码行号;

__FILE__:在源文件中插入当前源文件名;

__DATE__:在源文件中插入当前的编译日期

__TIME__:在源文件中插入当前编译时间;

__STDC__:当要求程序严格遵循ANSI C标准时该标识被赋值为1;

__cplusplus:当编写C++程序时该标识符被定义。

这几个宏比较有用~~~~~~~~

在调试程序时或编译时,__LINE__比较有用,可以用来打印逻辑错误的行号~~~~~~~,例子:

switch(x)

{

         1:

                   ....;

                   break;

 

         case 2:

                   .....;

                  break;

 

          default:

            printf("logic erro line number%d!/n",__LINE__);

            break;

}

又如用__DATE__和__TIME__可以插入编译时间。

代码:

void print_version_info(void)

{

         printf("Date Compiled:%s/n",__DATE__);

         printf("TimeCompiled:%s/n",__TIME__);

}

输出格式为:mm dd yy 和 hh:mm:ss

这样可以做到版本,自己也很清楚自己什么时候编译过~~ 

转载地址:http://jbsqi.baihongyu.com/

你可能感兴趣的文章
Design Accessible Web Sites: 36 Keys to Creating Content for All Audiences and Platforms
查看>>
Beginning Fedora: From Novice to Professional
查看>>
Learning ASP.NET 2.0 with AJAX: A Practical Hands-on Guide [ILLUSTRATED]
查看>>
Creating Motion Graphics with After Effects, Fourth Edition: Essential and Advanced Techniques
查看>>
Passive Optical Networks: Principles and Practice
查看>>
Beginning Java™ SE 6 Platform: From Novice to Professional
查看>>
Ethernet Networking for the Small Office and Professional Home Office
查看>>
Patterns for Computer-Mediated Interaction
查看>>
Mike Meyers' A+ Certification Passport, Third Edition
查看>>
The Rails Way
查看>>
MATLAB Demystified
查看>>
SharePoint 2007: The Definitive Guide [ILLUSTRATED]
查看>>
WCDMA for UMTS: HSPA Evolution and LTE
查看>>
Linux System Programming: Talking Directly to the Kernel and C Library [ILLUSTRATED]
查看>>
Prototype and script.aculo.us: You Never Knew JavaScript Could Do This!
查看>>
Beginning Joomla!: From Novice to Professional
查看>>
Understanding MySQL Internals
查看>>
Numerical Recipes 3rd Edition: The Art of Scientific Computing
查看>>
The Definitive Guide to the Microsoft Enterprise Library
查看>>
The Next Generation CDMA Technologies
查看>>