# Another tricky c++ preprocessor question

**URL:** <https://boards.straightdope.com/t/another-tricky-c-preprocessor-question/306454>\
**Category:** Factual Questions\
**Created:** [June 1, 2005, 9:35pm UTC](https://boards.straightdope.com/t/another-tricky-c-preprocessor-question/306454 "2005-06-01T21:35:36Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [June 2, 2005, 1:22am UTC](https://boards.straightdope.com/t/another-tricky-c-preprocessor-question/306454/21 "2005-06-02T01:22:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [June 2, 2005, 5:14am UTC](https://boards.straightdope.com/t/another-tricky-c-preprocessor-question/306454/22 "2005-06-02T05:14:07Z")

</div>

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.

[Previous page](https://boards.straightdope.com/t/another-tricky-c-preprocessor-question/306454.md?page=1)
