title: using an absolute pointer address as a template argument
body: <p>I have a template class which takes as its first template argument a foo * pointer. I'd like to instantiate one of these with a foo located at an absolute address, like so:</p>
  
  <pre><code>class foo
  {
      int baz;
  };
  
  template&lt;foo *f&gt; class bar
  {
  public:
      bar() {}
      void update() { /* ... */ }
  };
  
  // ....
  
  #define FOO_ADDR ((foo *)0x80103400)
  #define FOO_NULL ((foo *)0)
  
  foo testFoo;
  
  bar&lt;FOO_ADDR&gt; myFoo;        // fails with non-integral argument
  bar&lt;FOO_NULL&gt; huh;          // compiles, I was surprised by this
  bar&lt;&amp;testFoo&gt; test;         // compiles as expected (but not useful)
  </code></pre>
  
  <p>Does anyone know if it's possible without resorting to the linker and getting FOO_ADDR to be defined with external linkage?</p>
  
  <p>This is with the Keil ARM C/C++ Compiler version V5.06 update 1 (build 61), I've tried switching on C++11 mode but (apart from throwing a load of new errors in the system headers) it didn't change the behaviour.</p>
  
  <p>Update: here's the proposed solution (with the real code this time) using int casts</p>
  
  <pre><code>template&lt;uint32 PORT, uint32 BIT, uint32 RATE&gt; class LedToggle
  {
      uint32 mTicks;
      uint32 mSetReset;
  
      public:
  
      LedToggle()
      {
          mTicks = 0;
          mSetReset = 1 &lt;&lt; BIT;
      }
  
      void Update()
      {
          uint32 mask = ((mTicks++ &amp; RATE) - 1) &gt;&gt; 31;
          ((GPIO_TypeDef *)PORT)-&gt;BSRR = mSetReset &amp; mask;
          mSetReset ^= ((1 &lt;&lt; BIT) | (1 &lt;&lt; (BIT + 16))) &amp; mask;
      }
  };
  
  LedToggle&lt;(uint32)GPIOC, 13, 1023&gt; led;
  </code></pre>
  
  <p>It's pretty ugly, but it does work. I'd be interested to hear if anyone can improve on it?</p>