c - __FUNCT__ 有什么用?

标签 c conventions c-preprocessor

我在看一些 PETSc示例代码,我遇到了这个片段:

#undef __FUNCT__
#define __FUNCT__ "main"

就在 main 开始之前。

在每个函数(或只是 main?)之前设置 __FUNCT__ 或类似的东西是标准的 C 编程约定吗?

如果是这样,为什么要这样做?

最佳答案

来自 comments in the PETSc source code (${PETSC_DIR}/src/snes/examples/tutorials/ex3.c,第 33-40 行):

Note that immediately before each routine below, we define the macro __FUNCT__ to be a string containing the routine name. If defined, this macro is used in the PETSc error handlers to provide a complete traceback of routine names. All PETSc library routines use this macro, and users can optionally employ it as well in their application codes. Note that users can get a traceback of PETSc errors regardless of whether they define __FUNCT__ in application codes; this macro merely provides the added traceback detail of the application routine names.

关于c - __FUNCT__ 有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8859116/

相关文章:

gtk - 我应该在 GTK 中将应用程序 ID 设置为什么?

xcode - 抑制: "#warning is language extension"

c++ - 用 defined(X) 定义一个宏

C++:将 __PRETTY_FUNCTION__ 附加到 c 字符串

在 C 中更改字符串数组中的字符

c - 数组 Blackjack 排序错误 C 编程

c - 如何准备 UDP 数据报发送到服务器

c - OpenGL 2D 移动关系

c# - 我可以在 c# .NET 中强制使用 'this' 关键字吗?

ruby-on-rails - 在 Ruby 和/或 Rails 中在哪里定义自定义错误类型?