You have a very special case there. I think EEPROM_A##
is a family of macros. Macros work at the pre-processing level of the source file, a purely textual processing that occurs before calling the C compiler itself. I'll go into more detail about the preprocessor in this other answer .
In this case, there is not much to be done. At some point you need to access each of these macros ... What you can do is access these macros at an earlier time by populating a vector with those values.
If they are not macros, if they are variables, the language also does not provide any facility in this regard. C is a compiled language, and the name of the variables serves only as mnemonic so that the programmer (and the compiler too) can name a region of memory. After compiling, the name no longer exists and only the memory region exists, so there is not much to do about it.
In the case of variables, if they were compiled as if they were a vector, you can use a few pointers to do this in a loop. Recapping: Whether the compiled variables aligned as if they were a vector , something that depends on the library build from which you get those values. If you are compiling the library or if this is not explicitly written in its documentation, then we can assume that the following method is not reliable.
int i;
int *eeprom_a0_pt;
eeprom_a0_pt = &EEPROM_A0;
for (i = 15; i >= 0; i--) {
H8_3687_pulse(EEPROM_MASK(buf, *(eeprom_a0_pt + i) ));
}
But you can only do this if and only if it is guaranteed that the variables have been compiled inline as if they were a vector.
I looked for some alternative using the GCC extension of variable macros, but could not find anything that could do this processing.
The section below was written before I became aware of the tcc, serving then for the traditional C without external libraries; for more details, see the answer from the Wtrmute
But why all this? Simple, by C language design.
As I explained above, the name of the variables gets lost in the compilation. If macro, text substitution occurs before compilation.
To do this take the output of printf
and execute it correctly, you would need to evaluate ( evaluate in English) the expression. Making this evaluation is the equivalent of calling a compiler for that code snippet, also known as calling the eval
function available in some programming languages.
The practice of dynamic code generation to be evaluated in run time is something typical of Lisp and Bash, being not very common in C.