I want to generate nested for-loops instead of using recursion using the C preprocessor. The depth of this loop structure is bounded. An example nested for-loop with depth 3 is as below:
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < p; k++) {
// do_computation()
}
}
}
The depth can be between 2 to 10. I have many variations of do_computation() function, so manually writing code for every depth with the combination of the function is making the code look bloated.
Some of the answers in stack overflow point to using the boost preprocessor but unfortunately I will not be able to include boost in my application.
but unfortunately I will not be able to include boost in my application.why?I want to generate nested for-loops .. using the C preprocessorGreat. How do you want the API to look like?MAKE_3_LOOPS(i, j, k, m, n, p)?#define MAKE_3_LOOP(i, j, k, m, n, p) for (...) for (...) for (...). There are no loops in preprocessor, you can only use macros to replace code. Replace as in replace, literally, one for the other, with almost no logic. So, how do you want the preprocessor API to look like? What have you tried?intor{orstructin the entire thing for example.