title: MACROs in C++ to auto-generate a variable
body: <p>I have the code below, which is a <a href="https://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool" rel="nofollow">pintool</a> I am writing in <code>C++</code> this is a part of a <a href="https://svn.mcs.anl.gov/repos/performance/Gwalp/gwalpsite/pin/source/tools/Memory/allcache.cpp" rel="nofollow">code</a> that generates the ITLB part, of a single-core system. I am trying to adjust the code above, to make it work with multiple cores (for example 4)</p>
  
  <pre><code>#define CORE_NUM 4
  
  namespace ITLB
  {
      // instruction TLB: 4 kB pages, 32 entries, fully associative
      const UINT32 lineSize = 4*KILO;
      const UINT32 cacheSize = 32 * lineSize;
      const UINT32 associativity = 32;
      const CACHE_ALLOC::STORE_ALLOCATION allocation = CACHE_ALLOC::STORE_ALLOCATE;
  
      const UINT32 max_sets = cacheSize / (lineSize * associativity);
      const UINT32 max_associativity = associativity;
  
      typedef CACHE_ROUND_ROBIN(max_sets, max_associativity, allocation) CACHE;
  }
  LOCALVAR ITLB::CACHE itlb("ITLB 0", ITLB::cacheSize, ITLB::lineSize, ITLB::associativity);
  </code></pre>
  
  <p>i want to auto-generate the following:</p>
  
  <pre><code>LOCALVAR ITLB::CACHE itlb_0("ITLB 0", ITLB::cacheSize, ITLB::lineSize, ITLB::associativity);
  LOCALVAR ITLB::CACHE itlb_1("ITLB 1", ITLB::cacheSize, ITLB::lineSize, ITLB::associativity);
  LOCALVAR ITLB::CACHE itlb_2("ITLB 2", ITLB::cacheSize, ITLB::lineSize, ITLB::associativity);
  LOCALVAR ITLB::CACHE itlb_3("ITLB 3", ITLB::cacheSize, ITLB::lineSize, ITLB::associativity);
  </code></pre>
  
  <p>because of the CORE_NUM = 4. A possible solution is <code>MACROS</code> I guess! Any help?
  I am not very familiar using MACROs, could anyone suggest me a possible solution?</p>