I am currently implementing NASM-like preprocessor for my assembler, and I am wondering what is the correct way of handling recursively included files. From what I see, there are two ways to deal with it without hanging the preprocessor or even the OS:Set maximum include depth.Disallow including a file recursively (not to be confused with disallowing including a file twice).Also, as far as I can see, the second approach does essentially the same job, but produces nicer error messages. Compare output of Clang, when compiling file containing #include main.cpp only:In file included from main.cpp:1:[ repeated many times ]In file included from main.cpp:1:main.cpp:1:10: error: #include nested too deeply#include main.cppwith this (current way of handling this in my preprocessor; input is similar to above, does %include 1.mov.asm at line 6):In file /home/griwes/projects/reaverasm/tests/1.mov.asm in line 6:Error: file `/home/griwes/projects/reaverasm/tests/1.mov.asm` included recursively.The approach disallowing recursive inclusion produces - IMHO - more readable output.The question is: is there any preprocessor technique that would be killed by disallowing recursive inclusion? This question is language-agnostic, so feel free to give examples from any languages.
Are there any practical uses of allowing recursive inclusion of a file?
language agnostic;compiler
The Boost.Preprocessor library extends and abuses the C/C++ preprocessor in strange and wonderful ways.  One of its features is file iteration, which lets you #include a file multiple times with different macros #define'd each time, and they note that it can be useful (and is supported) for a file to iterate over itself.  (Search the examples here for BOOST_PP_IS_ITERATING.)  This is an example of (limited) recursion.