我在看一些 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/