I have the following code which is causing the -Wincompatible-pointer-types warning:
union SensorData { uint64_t raw_sensor_data; struct { uint16_t humidity_data; uint16_t temperature_data; }; } sensor_data; /* ... Bunch of other code ...*/ uint8_t *raw_sensor_data_bytes = &sensor_data.raw_sensor_data; uint8_t checksum = raw_sensor_data_bytes[0]; uint8_t sum = 0; for (uint8_t i = 1; i < 8; i++) { sum += raw_sensor_data_bytes[i]; }
The error gets called for the line
uint8_t *raw_sensor_data_bytes = &sensor_data.raw_sensor_data;
I understand why the error is getting called: it's getting called because I have a pointer that expects to be pointing to an 8 bit integer, when in reality it is pointing to a 64-bit integer; however, this is for (what I currently think) a good reason. I need to split that 64-bit integer into 8-bit segments, so I thought that it would be fine to create a pointer that would, in effect, divide the 64-bit integer into 8 8-bit segments; however, doing this is causing the aformentioned warning. Is there a more proper way to do what I am trying to do that would get rid of the warning, or is it possible for me to just simply override the warning in some way, or do I just have to ignore it?