I'm fairly new to the C preprocessor. Is it possible to change the case of an argument provided to a function-like #define
? For example, I want to write test(size)
and then involve "Size" in the resulting replacement.
You can't. Macros are expanded by the Preprocessor, which happens even before the code is compiled. It is a purely textual replacement. If you need to change something at runtime, just replace your macro with a real function call.
Function-like macros can take arguments, just like true functions. To define a macro that uses arguments, you insert parameters between the pair of parentheses in the macro definition that make the macro function-like. The parameters must be valid C identifiers, separated by commas and optionally whitespace.
The double-number-sign or token-pasting operator (##), which is sometimes called the merging or combining operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token, and therefore, can't be the first or last token in the macro definition.
If you accidentally redefine a name with a #define , the compiler silently changes the meaning of your program. With const or enum you get an error message.
No. The preprocessor can combine identifiers to form new ones, but it cannot modify an identifier.
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