I don't have a full understanding of variable types and usage, and I'm trying to figure out how to address a repeated error in my code. It compiles and works, but I'd like to eliminate the errors.
The error I get is:
comparison of integer expressions of different signedness: 'system_tick_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
In this line of code:
currentMillis = millis();
I declare the variable here:
int currentMillis;
I have tried to redefine the variable as unsigned int, unsigned long int, etc with no change.
how can I compare millis() or recast them so the error clears?
thx
int (aka int32_t) is a signed 32 bit integer but millis() returns an unsigned int (aka uint32_t).
The former has only half the possible positive numbers compared to the latter. Hence you may run into troubles when dealing with numbers > 2^31
Can you show the exact code where this warning pops up?
You show an assignment but then talk about a comparison, so I'd suspect the issue is not where you are looking at (or you define the same variable in multiple places).
For a unsigned compare all involved variables should be unsigned.
I'd rewrite your comparisons like this (when posting code snippets always provide the relevant variable definitions too)
const uint32_t msUdpReconnect = 60*60*1000; // renew UDP "connection" every hour
const uint32_t msIsrDebounce = 25; // milliseconds to ignore subsequent interrupts
uint32_t msIsrTime; // timestamp of last interrupt acceptance
uint32_t msUdpLastStart; // timestamp of last UDP "reconnect"
...
if (millis() - msIsrTime > msIsrDebounce) {
...
}
...
if (millis() - msUdpLastStart > msUdpReconnect) {
...
msUdpLastStart = millis();
}
BTW
Which closing curly brace?
I suspect the one that closes the if() { ... } block as that is the end of the statement. The compiler cannot be certain about the validity of a statement before it has fully parsed it and once it has it only gives you the place of where/when it found the error.
@ScruffR, Thanks! You always seem to have the answer. Your assistance has helped me thru dozens of hiccups over the past few years, you’re a huge asset to the community.
I’ll spend some time reworking the variables later today.
And yes, it was the Curly brace that closed the If block…