I would like to use an #include
directive with a file name that is passed as an externally defined macro.
E.g.
#include #FILE".h"
where FILE
would be defined as the string MyFile
(without quotes), resulting in
#include "MyFile.h"
The stringizing operator # cannot be used here as the symbol FILE
is not a macro argument. I have tried other approaches, to no avail.
Do you see a solution ?
In microeconomics, two goods are substitutes if the products could be used for the same purpose by the consumers. That is, a consumer perceives both goods as similar or comparable, so that having more of one good causes the consumer to desire less of the other good.
A macro is a fragment of code that is given a name. You can define a macro in C using the #define preprocessor directive. Here's an example. Here, when we use c in our program, it is replaced with 299792458 .
The #define directive substitutes expression for all further found entries of identifier in the source text. The identifier is replaced only if it is a separate token. The identifier is not replaced if it is part of a comment, part of a string, or part of another longer identifier.
In computer programming, a macro (short for "macro instruction"; from Greek μακρο- 'long, large') is a rule or pattern that specifies how a certain input should be mapped to a replacement output. Applying a macro to an input is known as macro expansion.
String literal concatenation happens two translation phases after #include
-directives are resolved; your approach cannot work. Instead, try something along the lines of
#define STRINGIZE_(a) #a
#define STRINGIZE(a) STRINGIZE_(a)
#define MYFILE stdio
#include STRINGIZE(MYFILE.h)
int main() {
printf("asdf");
}
Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With