这是什么(()) ?

在浏览 gcc 编译器源代码(gcc/c-family/c-praga.c)时,我看到:

typedef struct GTY(()) align_stack {
int                  alignment;
tree                 id;
struct align_stack * prev;
} align_stack;

不管我有多少年的 C 编程经验,这些比特: (())对我来说是完全陌生的。有人能解释一下这是什么意思吗?谷歌似乎没有找到它。

4712 次浏览

They are GCC internal "magic", i.e. part of the compiler implementation itself.

See this page which talks about their use. The macro is used to mark types for garbage-collection purposes. There can be arguments too, see this page for details.

UPDATE:: As pointed out by Drew Dorman in a comment, the actual double parenthesis are not part of the "internalness" of the GNU implementation; they're commonly used when you want to collect an entire list of arguments into a single argument for the called macro. This can be useful sometimes when wrapping e.g. printf(), too. See this question, for more on this technique.

In general, it's used with macros to shield commas. Given #define foo(a,b), the macro invocation foo(1,2,3) would be illegal. Using an extra pair of parenthesis clarifies which comma is shielded: foo((1,2),3) versus foo(1,(2,3)).

In this case, the GTY can take multiple arguments, separated by commas, but all these commas must be shielded. That's why the inner () surround all arguments.