News for hackers. Stuff that matters.
Re:Metaprogramming custom control structures in C by ay on Monday March 12, 2012 @05:16PM (#3695604)
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.
Re:Metaprogramming custom control structures in C by wcarss on Monday March 12, 2012 @05:50PM (#3695783)
(In agreement) It is tough to imagine the mental investment of another if-statement or more setup/teardown exceeding what's required to notice, understand, and debug one of these structures. You get slightly prettier code at a tremendous possible cost.

It feels like making people aware that they can use bazookas to kill butterflies. People are hopefully reasonable, but it can go very wrong.

All that said, cool.

Re:Metaprogramming custom control structures in C by fancydriving on Monday March 12, 2012 @10:46PM (#3696760)
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...), but those macros expand to readable code.

Re:Metaprogramming custom control structures in C by ay on Tuesday March 13, 2012 @07:26AM (#3697908)
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-...

Re:Metaprogramming custom control structures in C by mirsadm on Monday March 12, 2012 @07:52PM (#3696273)
Agreed. I would be very very careful about using this. The headaches it could cause far outweigh the (arguable) benefits.
Re:Metaprogramming custom control structures in C by nicolast on Monday March 12, 2012 @04:08PM (#3695193)
Re:Metaprogramming custom control structures in C by halayli on Tuesday March 13, 2012 @01:14AM (#3697134)
Better called, evil control structures. These macros add little value and makes it harder to understand the code.
Re:Metaprogramming custom control structures in C by raingrove on Tuesday March 13, 2012 @12:43AM (#3697074)
#define unless(x) if(!(x))
Re:Metaprogramming custom control structures in C by jff on Monday March 12, 2012 @08:05PM (#3696328)
Oh boy--macros!

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