`

C++之__LINE__, __FILE__, __FUNCDNAME__宏定义

c++ 
阅读更多
直接上结果


代码如下
#include <iostream>
#include <typeinfo>
#include <iomanip>
/*
@file 学习__LINE__,  __FILE__, __FUNCDNAME__  等宏定义的用法
@link http://msdn.microsoft.com/zh-cn/library/b0084kay.aspx
@link http://www.cnitblog.com/zouzheng/archive/2007/08/31/32691.aspx
*/

#pragma region 测试 函数名的三个宏,不是ANSI的标准宏
void testFunctionMacro (int a, float b) {
	std::cout << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCTION__" << "  :  " << __FUNCTION__ << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCDNAME__" << "  :  " << __FUNCDNAME__ << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCSIG__" << "  :  " << __FUNCSIG__ << std::endl;
}

void testFunctionMacro (int a) {
	std::cout << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCTION__" << "  :  " << __FUNCTION__ << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCDNAME__" << "  :  " << __FUNCDNAME__ << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCSIG__" << "  :  " << __FUNCSIG__ << std::endl;
}

// Demonstrates functionality of __FUNCTION__, __FUNCDNAME__, and __FUNCSIG__ macros
void testFunctionMacro() {
	std::cout << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCTION__" << "  :  " << __FUNCTION__ << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCDNAME__" << "  :  " << __FUNCDNAME__ << std::endl;
	std::cout << std::left << std::setw(16) << "__FUNCSIG__" << "  :  " << __FUNCSIG__ << std::endl;
}
#pragma endregion

#pragma region 测试__LINE__等宏,ANSI的标准宏
void test__ANSI__Macro() {
	std::cout << std::left << std::setw(16) << "__FILE__" << "  :  " << __FILE__ << std::endl;
	std::cout << std::left << std::setw(16) << "__LINE__" << "  :  " << __LINE__ << std::endl;
	std::cout << std::left << std::setw(16) << "__DATE__" << "  :  " << __DATE__ << std::endl;
	std::cout << std::left << std::setw(16) << "__TIME__" << "  :  " << __TIME__ << std::endl;
	std::cout << std::left << std::setw(16) << "__TIMESTAMP__" << "  :  " << __TIMESTAMP__ << std::endl;
	
}
#pragma endregion


void main() {
	test__ANSI__Macro();
	std::cout << std::endl;

    testFunctionMacro (1, 2);
    testFunctionMacro (1);
    testFunctionMacro();
}
  • 大小: 50.7 KB
分享到:
评论

相关推荐

    c++ 编程 几个有用的宏详解

    1. 打印错误信息 ...__FILE, __LINE, __FUNCTION是由编译器预定义的宏,其分别代表当前代码所在的文件名,行号,以及函数名。 可以在代码中加入如下语句来跟踪代码的执行情况: if(err) { printf(%s(%d)-%s\

    腾讯c/c++笔试题

    腾讯 c/c++笔试题 记了一部分 1、请定义一个宏,比较两个数a、b的大小,不能使用大于、小于、if语句 #define Max(a,b) ( a/b)?a:b 2、如何输出源文件的标题和目前执行行的行数 int line = __LINE__; char *...

    Visual C++ MFC 中常用宏的含义

    诊断消息的形式为: assertion failed in file in line 其中name是元文件名,num是源文件中运行失败的中断号。 在Release版中,ASSERT不计算表达式的值也就不中断程序。如果必须计算此表达式的值且不管环境如何那么...

    CLog,C++编写的一个日志类,与大家交流下

    //Adapter :可以用宏定义来进行适配。比如: // // #ifdef __CLOG_H__ // // #define DEBUG(VAR) mylog.Print(__FILE__, __LINE__, VAR, LOG_DEBUG) // // #else // // #define DEBUG(VAR) function //项目用的标准的...

    Visual C++ 编程资源大全(英文源码 其它)

    13.zip Autoincreasing build number 自动增加版本信息的宏(5KB)&lt;END&gt;&lt;br&gt;14,14.zip File Dialog Macro 文件对话框宏(6KB)&lt;END&gt;&lt;br&gt;15,15.zip Code Template add-in for Visual C++ 5.0 在VC5中可...

    编程参考宝典电子书

    Assertion failed: 0, file 源文件名, line 行号 Abnormal program termination 然后调用abort终止程序的执行。 在中,带参宏assert是被定义为条件编译的,如果在源文件中定义了宏NDEBUG,则即使包含了头文件,...

    editplus 代码编辑器html c++ jsp css

    【14】工具集成——编译器集成例子(Java、Borland C++、Visual C++、Inno Setup、nsis、C#) 【15】工具集成——让Editplus调试PHP程序———————-avenger,aukw 【16】工具集成——打造 PHP 调试环境(二)——...

    深入浅出MFC【侯捷】

    第3章 MFC六大关键技术之仿真 MFC类层次结构 Frame 1范例程序 MFC程序的初始化过程 Frame 2范例程序 RTTI(执行期类型识别) 类别型录网与CRuntimeClass DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC宏 Frame 3范例程序 Is...

    深入浅出MFC 2e

    标准菜单File/Edit/View/Window/Help 对话框 改用CEditView 第四篇 深入MFC程序设计 第8章 Document-View深入探讨 为什么需要Document-View(形而上) Document View Document Frame(View Frame) Document ...

    侯捷- -深入浅出MFC

    标准菜单File/Edit/View/Window/Help 对话框 改用CEditView 第四篇 深入MFC程序设计 第8章 Document-View深入探讨 为什么需要Document-View(形而上) Document View Document Frame(View Frame) Document ...

    C++出错提示英汉对照表

    Unexpected end of file in conditional started on line xxx ----从xxx 开始的条件语句尚未结束文件不能结束 Unknown assemble instruction ----------------未知的汇编结构 houjiuming Unknown option ---------...

    华为编程开发规范与案例

    在测试时发现程序死在循环之中,得到的错误记录是"Bus Error"(总线出错),由此可以说明出现了内存操作异常。 经过跟踪变量值发现循环变量i的阀值pSysHead-&gt;dbf_count的数值为0xFFFFFFFF,该值是从被破坏的内存...

    C语言编程要点

    5.31. 怎样取消一个已定义的宏? 92 5.32. 怎样检查一个符号是否已被定义? 93 5.33. C语言提供了哪些常用的宏? 93 第6章 字符串操作 93 6.1. 串拷贝(strcpy)和内存拷贝(memcpy)有什么不同?它们适合于在哪种情况下使用...

    Hacking Vim

    实现标签跳转,C/C++/Java编程时很有用。命令行下ctags –R *创立标签,Ctrl+]/Ctrl+O跳转,Ctrl+T返回 3.2 taglist 生成文件纲要,包括函数、关键字等。安装后使用:Tlist 3.3 A 实现头文件跳转。ctags不能查找...

    C 语言编程常见问题解答.chm

    5.31 怎样取消一个已定义的宏? 5.32 怎样检查一个符号是否已被定义? 5.33 C语言提供哪些常用的宏? 第6章 字符串操作 6.l 串拷贝(strcpy)和内存拷贝(memcpy)有什么不同?它们适合于在哪种情况下使用? ...

    代码语法错误分析工具pclint8.0

    选项还可以放在宏定义中,例如: #define DIVZERO(x) /*lint -save -e54 */ ((x) /o) /*lint -restore */ LINT的选项很多共有300多种,大体可分为以下几类: 1)错误信息禁止选项 该类选项是用于禁止生成某...

    你必须知道的495个C语言问题

    1.3 因为C语言没有精确定义类型的大小,所以我一般都用typedef定义int16和int32。然后根据实际的机器环境把它们定义为int、short、long等类型。这样看来,所有的问题都解决了,是吗? 1.4 新的64位机上的64位类型...

Global site tag (gtag.js) - Google Analytics