title: Setting the high bit of an integer type of unknown length
body: <p>I'm looking for a portable and elegant way to set the high bit of a pointer type in a situation where we don't know if the pointer will have 32, or 64 bits.</p>
  
  <p>I'm working on some legacy code that we inherited from a defunct company. It used to work in a 32 bit environment and now we need a working 64 bit version too. That means much larger pointers than before, and larger magic numbers to represent invalid values. Currently the best proposal will look broadly like this:</p>
  
  <pre><code>#if ENVIRONMENT_IS_32_BIT
  #define INVALID_PTR_CODE 0x80000000
  #else
  #define INVALID_PTR_CODE 0x8000000000000000
  #endif
  </code></pre>
  
  <p>As I say, I am hoping for something more elegant, and something that will work across different compilers (MSVC, gcc, clang at least). A perfect solution would work for any environment / size of pointer.</p>