Structs with enums are different in C and C++, why? : <p>The task is to send data by I2C from Arduino to STM32.</p>

<p>So I got Struct and Enums defined in Arduino using C++:</p>

<pre class="lang-cpp prettyprint-override"><code>enum PhaseCommands {
    PHASE_COMMAND_TIMESYNC  = 0x01,
    PHASE_COMMAND_SETPOWER  = 0x02,
    PHASE_COMMAND_CALIBRATE = 0x03
};

enum PhaseTargets {
    PHASE_CONTROLLER = 0x01,
    // RESERVED = 0x02,
    PHASE_LOAD1 = 0x03,
    PHASE_LOAD2 = 0x04
};

struct saatProtoExec {
    PhaseTargets   target;
    PhaseCommands  commandName;
    uint32_t       commandBody;
} phaseCommand;

uint8_t phaseCommandBufferSize = sizeof(phaseCommand);

phaseCommand.target = PHASE_LOAD1;
phaseCommand.commandName = PHASE_COMMAND_SETPOWER;
phaseCommand.commandBody = (uint32_t)50;
</code></pre>

<p>On the other side I got the same defined using C:</p>

<pre class="lang-c prettyprint-override"><code>typedef enum {
    COMMAND_TIMESYNC  = 0x01,
    COMMAND_SETPOWER  = 0x02,
    COMMAND_CALIBRATE = 0x03
} MasterCommands;

typedef enum {
    CONTROLLER = 0x01,
    // RESERVED = 0x02,
    LOAD1 = 0x03,
    LOAD2 = 0x04
} Targets;

struct saatProtoExec {
    Targets         target;
    MasterCommands  commandName;
    uint32_t        commandBody;
} execCommand;

uint8_t execBufferSize = sizeof(execCommand);

execCommand.target = LOAD1;
execCommand.commandName = COMMAND_SETPOWER;
execCommand.commandBody = 50;
</code></pre>

<p>And then I compare this Structs byte-by-byte:</p>

<pre class="lang-none prettyprint-override"><code>=====================
BYTE    | C++   |  C
=====================
Byte 0 -&gt; 0x3  -&gt; 0x3
Byte 1 -&gt; 0x0  -&gt; 0x2
Byte 2 -&gt; 0x2  -&gt; 0x0
Byte 3 -&gt; 0x0  -&gt; 0x0
Byte 4 -&gt; 0x32 -&gt; 0x32
Byte 5 -&gt; 0x0  -&gt; 0x0
Byte 6 -&gt; 0x0  -&gt; 0x0
Byte 7 -&gt; 0x0  -&gt; 0x0
</code></pre>

<p>So why bytes 1 and 2 are different?</p>
