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.cpp"
with 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.