Can't do bitwise shift on typdef structure

I’m trying to use bitwise shift to convert two bytes into an integer. This works fine on a normal integer, but it doesn’t work if my integer is part of a typdef structure. I get erratic readings and my arduino reboots.

typedef struct  {
  byte slaveID;
  byte cmdID;
  uint16_t mV;
  uint16_t temp;
  float myFloat;  // some float number
  uint32_t mS;   // milliseconds
} RemoteSensorData_t;

void loop() {
  RemoteSensorData_t sensor1; 
  if( getData( &sensor1 ))
  { Serial.println(sensor1.temp);  }

This works fine:

bool getData(RemoteSensorData_t* sensorInfo)
    uint16_t temperature;
    byte i2CData[PACKET_SIZE];
    // removed some i2CData code for brevity
    temperature  = i2CData[4] << 8;
    temperature |= i2CData[5];
    sensorInfo->temp = temperature;

This doesn’t work

bool getData(RemoteSensorData_t* sensorInfo)
    byte i2CData[PACKET_SIZE];
    // removed some i2CData code for brevity
    sensorInfo->temp  = i2CData[4] << 8;
    sensorInfo->temp |= i2CData[5];

Is typdef structure just not compatible with bitwise operations, or am I messing something up with pointers?

This doesn't work

What does it do? Let the magic smoke out? "This doesn't work" is pretty lame. The code does something, but you did not say what it does.

I mentioned that I was getting erratic readings and the Arduino reboots. When I do a Serial.println(sensor1.temp);, it's not the value I tried to store in it and the value changes on it's own. The Arduino will sometimes reboot and sometimes lock up.

The code you have written, "should" work. The likelihood is, you have some other problem than this.

I will try to replicate your problem later.

    byte i2CData[PACKET_SIZE];

Better show all your code. I wouldn’t surprise me if you were overrunning this array.

I figured it out. I was overrunning an array. I wasn't resetting the counter to zero when I called the function. The bit shifting works fine with typedef structure. Apparently is was just a coincidence that my sketch worked when I shifted bits into a regular variable instead of my struct.