robotology / yarp-device-realsense2

realsense2 device for YARP (https://www.yarp.it/)
Other
7 stars 10 forks source link

Compilation warning related to strict-aliasing rules #15

Open traversaro opened 3 years ago

traversaro commented 3 years ago

The compilation has the device raise this interesting warning:

1266 |             b = optionValue2Perc(RS2_OPTION_EXPOSURE, m_color_sensor, (float&) value, valToGet);
      |                                                                                ^~~~~
../src/devices/realsense2/realsense2Driver.cpp:1270:76: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1270 |             b = optionValue2Perc(RS2_OPTION_GAIN, m_color_sensor, (float&) value, valToGet);
      |                                                                            ^~~~~
../src/devices/realsense2/realsense2Driver.cpp:1280:85: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1280 |             b = optionValue2Perc(RS2_OPTION_WHITE_BALANCE, m_color_sensor, (float&) value, valToGet);
      |                                                                                     ^~~~~
../src/devices/realsense2/realsense2Driver.cpp:1284:81: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1284 |             b = optionValue2Perc(RS2_OPTION_SHARPNESS, m_color_sensor, (float&) value, valToGet);
      |                                                                                 ^~~~~
../src/devices/realsense2/realsense2Driver.cpp:1288:75: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1288 |             b = optionValue2Perc(RS2_OPTION_HUE, m_color_sensor, (float&) value, valToGet);
      |                                                                           ^~~~~
../src/devices/realsense2/realsense2Driver.cpp:1292:82: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1292 |             b = optionValue2Perc(RS2_OPTION_SATURATION, m_color_sensor, (float&) value, valToGet);
      |            

Not sure if anyone is interested in fixing it, but I open an issue to track it.

ste93 commented 3 years ago

An option that seems to work is:

ste93 commented 3 years ago

then row 217 must be a *perc = ...

traversaro commented 3 years ago

Feel free to open a PR if you like, thanks!