Another tricky c++ preprocessor question

Ah, it wasn’t clear that you were writing your own compiler. That does change things.

It can be done although by the time you do it, you’ll have wish you hadn’t.

Create another .h file which can track the number of inclusions using something like

#ifdef NINE
#define TEN
#endif
#ifdef EIGHT
#define NINE
#endif

#define ONE

On the 1st include, ONE will be defined, on the second include, TWO will be defined etc.

then, do

#ifdef TEN
#define COUNTER 10
#else
#ifdef NINE
#define COUNTER 9
#else

#endif

then

#define SIDE_MISSION_STATE(x) #include<count.h>
static const int x = COUNTER;

count.h can be generated using a code generator and you could scale it up to an arbitrary number. Since it all gets done in the preprocessor, compile times will be slightly longer but the file size will be unaffected.