VC好象只支持宏__FILE__,__LINE__,但不支持__FUNCTION__,不知有没有好的替代方法?

rtdb 2004-08-23 05:00:46
RT
...全文
312 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2004-08-23
  • 打赏
  • 举报
回复
__FILE__
This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in #include or as the input file name argument. For example, "/usr/local/include/myheader.h" is a possible expansion of this macro.

__LINE__
This macro expands to the current input line number, in the form of a decimal integer constant. While we call it a predefined macro, it's a pretty strange macro, since its "definition" changes with each new line of source code.
__FILE__ and __LINE__ are useful in generating an error message to report an inconsistency detected by the program; the message can state the source line at which the inconsistency was detected. For example,

fprintf (stderr, "Internal error: "
"negative string length "
"%d at %s, line %d.",
length, __FILE__, __LINE__);

An #include directive changes the expansions of __FILE__ and __LINE__ to correspond to the included file. At the end of that file, when processing resumes on the input file that contained the #include directive, the expansions of __FILE__ and __LINE__ revert to the values they had before the #include (but __LINE__ is then incremented by one as processing moves to the line after the #include).

A #line directive changes __LINE__, and may change __FILE__ as well. See Line Control.

C99 introduces __func__, and GCC has provided __FUNCTION__ for a long time. Both of these are strings containing the name of the current function (there are slight semantic differences; see the GCC manual). Neither of them is a macro; the preprocessor does not know the name of the current function. They tend to be useful in conjunction with __FILE__ and __LINE__, though.

jruv 2004-08-23
  • 打赏
  • 举报
回复
snaill() ,强!
holyeagle 2004-08-23
  • 打赏
  • 举报
回复
可能是函数的通用性不强吧,如果是全局的的变量,就没有函数,不能相应定位了。而且,函数在最初的词法上不好分析,因为这时候只是分析语法,还没到函数分析,遇到语法错误就可以停止,不用再分析函数,如果这时候去定位函数会多作无用的工作。
snaill 2004-08-23
  • 打赏
  • 举报
回复
Microsoft-Specific Predefined Macros

__FUNCTION__
Valid only within a function and returns the undecorated name of the enclosing function (as a string). __FUNCTION__ is not expanded if you use the /EP or /P compiler option.
DentistryDoctor 2004-08-23
  • 打赏
  • 举报
回复
使用VC7.0/7.1呀。
newsb 2004-08-23
  • 打赏
  • 举报
回复
vc确实没有,可能微软觉得file 和line就能唯一确定位置了,所以没有加入func的宏
flyelf 2004-08-23
  • 打赏
  • 举报
回复
vc没有这个宏,关注ing

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧