News for hackers. Stuff that matters.
Re:Why does this C program compile? by cnvogel on Wednesday December 19, 2012 @03:10PM (#4944511)
There's the "##" operator with which you can glue together identifiers with the preprocessor.

  #define yell(i,l,o,v,e,u) o##v##i##l
  yell(i,l,o,v,e,u) will turn into the identifier ovil.
And billy_bot just uses the yell-macro to produce a "main" identifier.

  #define billy_bob yell(i,n,m,a,t,e)

  yell(i,l,o,v,e,u) --> o ## v ## i ## l
  yell(i,n,m,a,t,e) --> m ## a ## i ## n
So billy_bop is main.

Why is this features useful at all? When you actually want to programmatically create function names, type names, struct names in preprocessor generated code.

     #define ENCAPS_STRUCT(type,name)  struct encaps_##type { type name; }
     ENCAPS_STRUCT(int,a);
will generate...

     $ cc -E test.c
     # 1 "test.c"
     # 1 "<built-in>"
     # 1 "<command-line>"
     # 1 "test.c"

     struct encaps_int { int a; };

There are no comments on this comment yet.