Why does the LINE_NAME macro even work if JOIN is declared after it in the file?
Macros are not functions, when you call them compiler expands them, and there compiler at the using point knows about all defined macros.
Why is it necessary to use both the JOIN and _DO_JOIN macros in order to get the correct result? Having this level of indirection in the macros seems very strange.
Because __LINE__
itself is a macro, it needs two level expanding.
Otherwise the output is not prefix1234
it will be prefix__LINE__
.
it's useful to read this answer too, and this thread.