title: C++ Impossible pointer behavior
body: <p>I'm writing something like Java, and I have problem with pointer (- - )
  I have a struct:</p>
  
  <pre><code>struct _lnHeader32
  { unsigned char signature[2]; //LN
    unsigned char architecture;
    unsigned int length; //Without _lnHeader
    unsigned int lnHeaderLength;
    unsigned char permissions;
    unsigned char typeOfExecutable;
    unsigned int flowSegment;
    unsigned int dataSegment;
    unsigned int loaderSegment;
    unsigned int cleanerSegment;
    unsigned int errorSegment;
    unsigned int exportTable;
    unsigned int importTable;
    unsigned int authenticationTable; //Encrypt it with GPG.
    unsigned int loaderTable;
  };
  </code></pre>
  
  <p>I load executable, which is in little-endian, by using std::fstream:</p>
  
  <pre><code>lnFile.open(argv[1], std::fstream::in | std::fstream::binary);
  if (false == lnFile.is_open())
   throw (unableToOpen);
  lnSize = getFileSize(lnFile);
  lnImage = new (std::nothrow) unsigned char [lnSize];
  if (0 == lnImage)
   throw (noMem);
  lnFile.read(reinterpret_cast&lt;char*&gt;(lnImage), lnSize); //#1 Possible mistake?
  if (!lnFile)
   throw (unableToRead);
  lnFile.close();
  </code></pre>
  
  <p>Then I point _lnHeader32* to allocated lnImage:</p>
  
  <pre><code>lnHeader32 = reinterpret_cast&lt;_lnHeader32*&gt;(lnImage);
  </code></pre>
  
  <p>At final I print whole struct by two methods:</p>
  
  <pre><code>//Method 1
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(lnImage) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(lnImage+2) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(lnImage+3) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(lnImage+7) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(lnImage+11) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(lnImage+12) &lt;&lt; "\n\n";
  
  //Method 2    
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(&amp;lnHeader32-&gt;signature) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(&amp;lnHeader32-&gt;architecture) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(&amp;lnHeader32-&gt;length) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(&amp;lnHeader32-&gt;lnHeaderLength) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(&amp;lnHeader32-&gt;permissions) &lt;&lt; "\n";
  std::cout &lt;&lt; reinterpret_cast&lt;unsigned int*&gt;(&amp;lnHeader32-&gt;typeOfExecutable) 
                                                                    &lt;&lt; "\n\n";
  </code></pre>
  
  <p>It gives Me output like:</p>
  
  <pre><code>0xe8b260
  0xe8b262
  0xe8b263 &lt;---
  0xe8b267
  0xe8b26b
  0xe8b26c
  
  0xe8b260
  0xe8b262
  0xe8b264 &lt;--- Should be 0xe8b263 | Here starts problem
  0xe8b268
  0xe8b26c
  0xe8b26d
  </code></pre>
  
  <p>It prints well lnHeader32's fields by using first method, but I prefer to use second method. I calculated everything few times. Why it is happening?
  Executable is generated by compiler done in perl, has it any influence?</p>