title: Should I use an enum or multiple const for non-sequential constants in c++?
body: <p>I'm writing porting file-io set of functions from c into a c++ class.  "Magic numbers" (unnamed constants) abound.  </p>
  
  <p>The functions read a file header which has a number of specific entries whose locations are currently denoted by magic numbers.</p>
  
  <p>I was taught by a veteran programmer a couple years back that using "magic numbers" is inherently evil, and thus, I have since tried to avoid using unnamed constants in my port.  So I want to create some sort of list of constants of where the entries are stored.  </p>
  
  <p>So far I've come up with two solutions that seem relatively safe -- use a namespace enclosed set of constants or a namespace enclosed enum.  </p>
  
  <p>Can I use either solution safely?  Would there be any advantages to one over the other?</p>
  
  <p>e.g.<br>
  <strong>OPTION 1</strong></p>
  
  <pre><code>namespace hdr_pos {
     const unsigned int item_1_pos=4;
     const unsigned int item_2_pos=8;
     const unsigned int item_3_pos=12;
     const unsigned int item_4_pos=24;
     const unsigned int item_5_pos=32;
  };
  </code></pre>
  
  <p><strong>OPTION 2</strong></p>
  
  <pre><code>namespace hdr_pos {
     enum e {
        item_1_pos=4,
        item_2_pos=8,
        item_3_pos=12,
        item_4_pos=24,
        item_5_pos=32
     };
  };
  </code></pre>
  
  <p>Is there anyway to prevent duplicates, to catch if I change the positions due to a future update to the file header, but forget to change one of them?</p>
  
  <p>Please keep this factual and non-subjective.  If there is no advantage you know of, feel free to answer that.</p>
  
  <p><strong>Note:</strong> I would use more descriptive names, of course, in my actual implementation; I just called things item_&lt;#>_... for examples sake...</p>