Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this (( ))?

Tags:

c++

c

While browsing through the gcc compiler source code (gcc/c-family/c-pragma.c) I see:

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

and regardless of having lots of C programming years behind me, these bits: (()) are totally unknown to me yet. Can someone please explain what they mean? Google does not seem to find it.

like image 554
Ferenc Deak Avatar asked Feb 15 '13 08:02

Ferenc Deak


2 Answers

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.

like image 69
unwind Avatar answered Nov 12 '22 03:11

unwind


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.

like image 44
MSalters Avatar answered Nov 12 '22 02:11

MSalters