News for hackers. Stuff that matters.
Re:Why does this C program compile? by kevinnk on Wednesday December 19, 2012 @02:50PM (#4944396)
>#include <stdio.h>

>#define yell(i,l,o,v,e,u) o##v##i##l

defines a macro called yell. The preprocessor operator ## concatenates it's operands together so something like ma##in gets transformed into main.

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

defines a macro called billy_bob that simply expands to the macro yell. When we call yell with the given arguments we get m##a##i##n (look at the order of the arguments for yell) which gets transformed into main.

>billy_bob()

Expanding the macro turns this line into main().

>{

> printf("no main in da house!");

>}

So now we've declared a main function that just prints "no main in da house!".

There are no comments on this comment yet.