Is it possible to write a #define
that defines a #define
?
For example:
#define FID_STRS(x) #x
#define FID_STRE(x) FID_STRS(x)
#define FID_DECL(n, v) static int FIDN_##n = v;static const char *FIDS_##n = FID_STRE(v)
But instead:
#define FID_DECL2(n, v) #define FIDN_##n v \
FIDS_##n FID_STRE(v)
FID_DECL
works fine but creates two static variables. Is it possible to make FID_DECL2
work and having define two defines?
#define is a preprocessor directive that is used to define macros in a C program. #define is also known as a macros directive. #define directive is used to declare some constant values or an expression with a name that can be used throughout our C program.
Put them where you need them. If you need it only for one file then put it at the top of that file. If you need it for multiple files then put it in a header file. And if defines are needed only in one function: inside the function or at the top of the file?
printf("%d", 5);
Variables can be declared as constants by using the “const” keyword before the datatype of the variable. The constant variables can be initialized once only. The default value of constant variables are zero. A program that demonstrates the declaration of constant variables in C using const keyword is given as follows.
No; preprocessing is performed in a single pass. If you want or need more advanced behavior, consider using another tool to preprocess the source, like m4.
Further, the #
in the replacement list (at the beginning of #define FIDN...
would be parsed as the #
(stringize) operator: the operand of this operator must be a named macro parameter, which define
is not.
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