Post topics, source code that relate to the Arduino Platform

User avatar
By martinayotte
#25002
LauBaz wrote:ESP.deepSleep(60*60*1000000); //Compiler error: "warning: integer overflow in expression [-Woverflow]"
ESP.deepSleep(3600000000); //no error, this seems to work (although I have not waited an hour to wait for it). I have even tried it all the way to 4294967295 (2^32 -1) and it compiles fine.

What am I missing there?

Simply that last bit of int or long is the +/- sign, so number part is 31 bits not 32 bits. If you cast them to "unsigned int", you won't get the warning.
User avatar
By LauBaz
#25008
martinayotte wrote:
Simply that last bit of int or long is the +/- sign, so number part is 31 bits not 32 bits. If you cast them to "unsigned int", you won't get the warning.


Ah! Excellent point, thank you. I fixed it by doing the following, forcing an unsigned int to my operation:

ESP.deepSleep(60U*60*1000000); //U for unsigned int