如何在文件系统中找到可变宏实现

How to find variadic macro implementation in file system

我遇到过这个宏:__VA_ARGS__ - 文档中的可变参数宏。它用于扩展宏定义中的三重点(如 define SMF(...) fprintf(stdout, __VA_ARGS__),但是当我想找到它的实现时(How does it expand all agruments given - just its implementation) - 我试过 sudo cd /; grep -r '#define __VA_ARGS__(提到 #define,因此它不会仅在 'use' 中发出该宏,而是在其定义中发出)。它搜索了很长时间,但它只给了我对某些目录没有权限(例如 sys/kernel/debug/block/loop17/hctx0/cpu3/read_rq_list - 即使用 sudo 触发 - 不知道为什么,但那是另一个故事)。仍然没有告诉在哪里看(在什么文件中)。因此,如果它没有从根目录中找到该宏(并递归地查找其他目录),那么我应该去哪里查找?

PS:我知道当宏以双下划线开头时,它要么是系统宏,要么是编译器(gcc)宏,但是当我用 gcc 做类似的时候(grep __VA_ARGS__ via man gcc | grep ...), 即使没有成功。

可变参数宏是 C11 语言规范的一部分(阅读 n1570), and of the GNU cpp preprocessor

它们在最近的 GCC 源代码的 GCC compiler itself. Beware, that compiler is very complex. Read about GCC internals and glance into the source code of the GCC compiler since it is free software. Look inside the libcpp/ directory 中实现。

当然,您随后想要 download the source code of GCC(不仅仅是可执行文件)。

然后,查看GCC resource center (by several Indian academics) to start understanding GCC. This will require an important effort (at least several months, and probably several years) from your part, since GCC has dozen of millions of source code lines. But trying to understand the organization of GCC is an exciting adventure. You may want to ask focused questions on one of the GCC mailing lists

我几年前写过(在过时的GCC MELT project) many slides about GCC internals. The details are obsolete. But most ideas are still relevant, and I guess that some figures could still help you to understand GCC. More recently, my Bismon draft report内给出了一些解释(与最近版本的GCC有关)。

您可能有兴趣玩(并编写自己的)GCC plugins