Is there any practical use for macro expansion on an "#include" line?
For example, a header file like
// calculated_include.h
#define THE_STRING "Hello, World!\n"
Then a C or C++ file like
// calculated_include.c
#define HEADER_MACRO "calculated_include.h"
#define STDIO <stdio.h>
#include STDIO
#include HEADER_MACRO
int main(void){
printf("%s", THE_STRING );
}
Then from the command line I do
make calculated_include
./calculated_include
and it prints out, as you've probably already guessed,
Hello, World!
I see some people call macro expansion on an "#include" line "calculated includes" or "computed includes"; is there a better name?
I see that one person wanted to use text substitution in a "#include" file so a filename specified on the gcc command line with the "-D" option would get substituted into an "#include" statement ( How can I specify an include file from the GCC Command Line? ). But it seems to me that specifying that filename directly with the "-include" command-line option instead ( Include header files using command line option? and "Options Controlling the Preprocessor") would be simpler and work just as well.
Is there any other use for macro expansion on an "#include" line?