且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不带#define捕获__LINE__和__FILE__

更新时间:2022-06-13 02:35:42

实际上,当您要使用行号和文件名时,预处理器是唯一的选择。

Actually the preprocessor is the only choice when you want to work with line numbers and filenames.

对于编译器,无法使用行号和文件名作为函数调用的参数(或将它们存储在变量中)。

For the compiler it's not possible to use line numbers and filenames as arguments for function calls (or storing them in a variable).

在我的公司中,日志记录存在完全相同的问题。最后,我们用一个外部脚本扫描源文件,然后构建适当的函数来调用。

In my company we had the exactly same issue with logging. We ended up with an external script scanning the source files and then building proper functions to call.