Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a C++ compiler re-order elements in a struct
    primarykey
    data
    text
    <p>Can a C++ compiler (specifically g++) re-order the internal elements of a struct?</p> <p>I'm seeing some strange behaviour where I have a structure that contains something like the following:</p> <pre><code>Struct SomeStruct{ ... ... long someLong; long someLongArray[25]; unsigned long someUnsignedLong; unsigned long someUnsignedLongArray[8]; unsigned long int someUnsignedLongInt; ... ... }; </code></pre> <p>When I write output this to file, the order of <em>someUnsignedLongArray</em> and <em>someLongArray</em> seem to be reversed (i.e. the elements in <em>someLongArray[]</em> appear after <em>someUnsignedLong</em> and the elements of <em>someUnsignedLongArray[]</em> appear after <em>someLong</em>). Is this possible??</p> <p>Thanks</p> <hr> <p>Update: As requested, I am writing out the structure using the following:</p> <pre><code>int fd = open(fspec,O_RDWR|O_CREAT|O_TRUNC,0666); int writeRes = write(fd,(char *)&amp;someStruct,sizeof(SomeStruct)); </code></pre> <p>For completeness, here is the full struct:</p> <pre><code>struct SomeStruct{ byte someByte; byte someByteArray[6]; char someChar; char someCharArray[5]; char someCharArrayArray[3][5]; short someShort; signed short someShortArray[2]; unsigned short someUnsignedShort; unsigned short someUnsignedShortArray[8]; int someInt; int someIntArray[3]; int someIntArrayArrayArrayArray[4][3][2][6]; int *pSomeInt; unsigned int someUnsignedInt; unsigned int someUnsignedIntArray[9]; long someLong; long someLongArray[25]; unsigned long someUnsignedLong; unsigned long someUnsignedLongArray[8]; unsigned long int someUnsignedLongInt; long long someLongLong; long long someLongLongArray[5]; bool someBool; bool someBoolArray[3]; unsigned long long someUnsignedLongLong; unsigned long long someUnsignedLongLongArray[5]; unsigned long long someUnsignedLongLongArrayArray[5][2]; unsigned long long int *pSomeUnsignedLongLongInt; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload