Alex Rivera | Logout

How to write a while loop with the C preprocessor?

Asked 2008-11-26T00:05:29.620
83

I am asking this question from an educational/hacking point of view, (I wouldn't really want to code like this).

Is it possible to implement a while loop only using C preprocessor directives. I understand that macros cannot be expanded recursively, so how would this be accomplished?

Edit
Report

1 Answer

7

I use meta-template programming for this purpose, its fun once you get a hang of it. And very useful at times when used with discretion. Because as mentioned its turing complete, to the point where you can even cause the compiler to get into an infinite loop, or stack-overflow! There is nothing like going to get some coffee just to find your compilation is using up 30+ gigabytes of memory and all the CPU to compile your infinite loop code!

answered 2008-11-26T01:28:50.810

Your Answer