

Metaprogramming custom control structures in C - AndrewDucker
http://www.chiark.greenend.org.uk/~sgtatham/mp/

======
ay
As someone who had to single-step through this kind of code in gdb, and who
had to use the series of fgreps because the cscope is not smart enough to
digest these constructs, I can only suggest - weigh the pros and cons before
using this technique, especially the fancier parts of it.

~~~
fancydriving
I think a good rule of thumb is to only use the preprocessor to generate code
that you would be comfortable writing yourself. Spaghetti produced by macros
is still spaghetti.

The article reminded me of queue.h from BSD ([http://www.openbsd.org/cgi-
bin/cvsweb/src/sys/sys/queue.h?re...](http://www.openbsd.org/cgi-
bin/cvsweb/src/sys/sys/queue.h?rev=1.35;content-type=text%2Fplain)), but those
macros expand to readable code.

~~~
ay
These macros are nothing compared to what I consider a _real_ abuse of the
preprocessor - a whole functional language implemented just by that! Search
for "chaos-pp" in this entry (which has plenty of other wonders too!):

[http://stackoverflow.com/questions/652788/what-is-the-
worst-...](http://stackoverflow.com/questions/652788/what-is-the-worst-real-
world-macros-pre-processor-abuse-youve-ever-come-across)

------
nicolast
I did something quite similar to this in [1] and [2] some time ago.

[1]
[https://github.com/Incubaid/crakoon/blob/master/src/arakoon....](https://github.com/Incubaid/crakoon/blob/master/src/arakoon.h#L277)
[2]
[https://github.com/Incubaid/crakoon/blob/master/src/arakoon....](https://github.com/Incubaid/crakoon/blob/master/src/arakoon.h#L316)

------
halayli
Better called, evil control structures. These macros add little value and
makes it harder to understand the code.

------
raingrove
#define unless(x) if(!(x))

------
jff
Oh boy--macros!

Just say no to crack, kids, or you'll end up like the Linux kernel.

