title: Structs Being Weird - C++
body: <p>I have been having alot of trouble with this stupid struct. I don't see why it is doing this, and I am really not sure how to fix it. The only way I know how to fix it, is by removing the struct and doing it some other way(which I don't want to do).</p>
  
  <p>So I am reading data from a file, and I am reading it in to a struct pointer all at once. It seems like the offset/pointer of my 'long long' gets messed up everytime. View in details below.</p>
  
  <p>So here is my struct:</p>
  
  <pre><code>struct Entry
      {
          unsigned short type;
          unsigned long long identifier;
          unsigned int offset_specifier, length;
      };
  </code></pre>
  
  <p>And here is my code for reading all the crap into the struct pointer/array:</p>
  
  <pre><code>Entry *entries = new Entry[SOME_DYNAMIC_AMOUNT];
  fread(entries, sizeof(Entry), SOME_DYNAMIC_AMOUNT, openedFile);
  </code></pre>
  
  <p>As you can see, I write all that into my struct array. Now, I will show you the data I am reading(for the first struct in this example).</p>
  
  <p><img src="https://i.stack.imgur.com/pLj7Z.png" alt="The bytes I am reading."></p>
  
  <p>So this is the data that is going into the first element in 'entries'. The first item(the short, 'type'), seems to be read fine. After that, when the 'identifier' is read, it seems like the whole struct is shifted X amount of bytes. Here is a picture of the first element(after reversing the endian):</p>
  
  <p><img src="https://i.stack.imgur.com/0cdjs.png" alt="enter image description here"></p>
  
  <p>And here is the data in memory(the red square is where it begins):</p>
  
  <p><img src="https://i.stack.imgur.com/i2gnQ.png" alt="enter image description here"></p>
  
  <p>I know that was a bit confusing, but I tried to explain it as well as possible. Thanks for any help, Hetelek. :)</p>