mathertel / DmxSerial2

An Arduino library for sending and receiving DMX RDM packets.
BSD 3-Clause "New" or "Revised" License
99 stars 30 forks source link

Build warning when Compler Warnings = All (Part 2) #19

Closed g0uus closed 6 years ago

g0uus commented 6 years ago

If the Arduino Compiler Warnings option is set to YES, the following warning is generated -

C:\Users\grh\Google Drive\Arduino\libraries\DmxSerial2\src\DMXSerial2.cpp: In member function 'uint8_t DMXSerialClass2::readRelative(unsigned int)':

C:\Users\grh\Google Drive\Arduino\libraries\DmxSerial2\src\DMXSerial2.cpp:395:16: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]

   if ((channel >= 0) && (channel < _initData->footprint)) {

                ^

This occurs because channel is declared as unsigned int.

The fix is simply to change the statement to

   if (channel < _initData->footprint) {
peternewman commented 6 years ago

See the discussion here https://github.com/mathertel/DmxSerial2/issues/18#issuecomment-430237661

In this case you probably want to add a comment saying what the old test was and maybe why it's been removed.

mathertel commented 6 years ago

Good suggestion. I added a comment. This change has no effect on code size - I assume the compiler removed it already during optimization. https://github.com/mathertel/DmxSerial2/commit/150d485fea5b186fe0def02bdace468f80f5b742

Thanks.