Makuna / Rtc

Arduino Library for RTCs, Ds1302, Ds1307, Ds3231, Ds3232, Ds3234 and Pcf8563/BM8563 with deep support. Please refer to the Wiki for more details. Please use the Github Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
355 stars 126 forks source link

warning: comparison of integer expressions of different signedness #209

Open kinlougha opened 1 month ago

kinlougha commented 1 month ago

Describe the bug Receive this warning when compile OnStepX under VSCode:

In file included from .pio\libdeps\teensy41\RTC\src\RtcDateTime.cpp:29: .pio\libdeps\teensy41\RTC\src\RtcDateTime.h: In member function 'RtcDateTime RtcDateTime::operator+(int32_t) const': .pio\libdeps\teensy41\RTC\src\RtcDateTime.h:168:41: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'long int'} and 'uint32_t' {aka 'long unsigned int'} [-Wsign-compare]
168 | if (seconds < 0 && abs(seconds) > totalSeconds)

**Development environment

Correction: Change "int32_t" for "uint32_t" on line 164 of RtcDateTime.h

Thanks.

Makuna commented 1 month ago

That is not a correct fix. This is to support the ability for a statement like

int32_t offset = -60; // one hour back, may latter be changed to forward time
//blah blah
time += offset;

the abs() will need to be cast since it seems the platform you are using doesn't have a unsigned abs(signed) version for the compiler to select.

kinlougha commented 1 month ago

OK I understand, i open a case to PJRC with this info and close this case.

Thanks.

kinlougha commented 1 month ago

Hello,

This is the answer from PJRC : https://forum.pjrc.com/index.php?threads/warning-message-at-compile.75017/

Makuna commented 1 month ago

https://github.com/Makuna/Rtc/pull/210

kinlougha commented 1 month ago

Hi Michael,

I test the solution, with the master branch, on 2 platforms (Teensy 4.1 and ESP32) and no more warning from the library.

This case is close for me.

Thanks.

Makuna commented 1 month ago

Leave it open (its marked as Pending). I will close it when I publish the next update.

kinlougha commented 1 month ago

Sorry Michael, I leave it open, I understand.

Thanks.