[Edit: See salem c's post]
You can't do that (Edit: in that way, see salem c's answer). _DIGIT_x is literally the character 'x' at the end, as part of the identifier. It doesn't know you're trying to use the other macros.
First, why do you need to do this? What problem are you actually trying to solve?
Using macros in arcane ways is usually frowned upon.
You could have a lookup table, something like:
First I would suggest removing the (_). It is very easy to conflict with a definition in a header file. Best to leave variable starting with 1 or 2 (_) to the header files.
In VS 2017 my error message says "_DIGIT': macro redefinition". Which tells me that "_DIGIT" is already defined in some header file.
When I removed the beginning (_)s from everything it compiled without any warnings or errors.
Thanks salem c for the example. I knew about ## but I thought it had to be used with string literals for some reason. It's actually more elegant than I thought it would be.
#define macros are evaluated at compile time. For _DIGIT(i) to work, it would have to be evaluated at runtime because the program doesn't know the value of i until the program is running.
Why not just use the actual digit instead of the macro? Is the real problem something more complex?
It would use RAM either way. Data isn't free, it's just that it would be stored in a static location instead if you did _DIGIT(3).
Edit: Actually, depending on usage, it may in fact just hardcode the numbers in the assembly instructions. But that couldn't be done for a for loop w/ i anyway.