I have a list defined as a preprocessor value #define LIST 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
. I want to write a macro that gets an index 0 or 1 and evaluates to a subset of the LIST
such that for index 0 it will evaluate to 0, 2, 4, 6, 8
and for index 1 it will evaluate to 1, 3, 5, 7, 9
. It is guaranteed that LIST
's length is even but I don't know the content in advance (it is auto generated by the users of the library I supply). This question is a follow up on this question
#define LIST 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
#define MACRO(index) \
use LIST and index
// For LIST that given in the example
printf("%d %d %d %d %d\n", MACRO(0)); // print 0 2 4 6 8
printf("%d %d %d %d %d\n", MACRO(1)); // print 1 3 5 7 9