title: Cache line padding for variables that are a multiple of cache line size
body: <p>I am creating a very fast multi-threaded discrete event simulation framework. The core of the framework uses atomics and lockless programming techniques to achieve very fast execution across many threads. This requires me to align some variables to cache lines and pad the remaining cache line space so that I don't have cache line contention. Here is how I do it:</p>
  
  <pre><code>// compute cache line padding size
  constexpr u64 CLPAD(u64 _objSize) {
    return ((_objSize / CACHELINE_SIZE) * CACHELINE_SIZE) +
        (((_objSize % CACHELINE_SIZE) &gt; 0) * CACHELINE_SIZE) -
        _objSize;
  }
  
  alignas(CACHELINE_SIZE) MyObject myObj;
  char padding[CLPAD(sizeof(myObj))];
  </code></pre>
  
  <p>This works great for me, but I stumbled upon an issue today when I was using this methodology for a new object type. The CLPAD() function returns the amount of chars needed to pad the input type up to the next cache line. However, if I put in a type that is exactly sized a multiple of number of cache lines, the CLPAD returns 0. If you attempt to create a zero sized array, you get this warning/error:</p>
  
  <pre><code>ISO C++ forbids zero-size array 'padding'
  </code></pre>
  
  <p>I know I could modify CLPAD() to return CACHELINE_SIZE in this case, but then I'm burning a cache line worth of space for no reason.</p>
  
  <p>How can I make the declaration of 'padding' disappear if CLPAD returns 0?</p>