compiler warning comparison between signed and unsigned

Status
Not open for further replies.

DaQue

Well-known member
I'm staring at this and don't see the problem reported:

checkWipe.h: In function 'void checkWipe()':
checkWipe.h:22: warning: comparison between signed and unsigned integer expressions
for (int x = 0; x <= (2047 - sizeof(int)); x = x + sizeof(int)) {

^

The lines of code are:

for (int x = 0; x <= (2047 - sizeof(int)); x = x + sizeof(int) ) {
EEPROM.put( x, (int)0 );
} //endfor

This is to wipe the full eeprom on a T3.2. I didn't see a function to do that in EEPROM.h.
Is sizeof() unsigned for some reason?
 
Thanks. I couldn't imagine sizeof() ever returning over 2^31-1. I just did some looking and it's std::size_t in a c++ reference which is implementation dependent but unsigned. The Arduino reference web page didn't say anything about a return type so I assumed it was int. I know enough programming to be dangerous but not efficient. You've been a great help with my questions Thanks again.
 
size_t which is the type of sizeof is required to be unsigned by the ISO C standard (and C++ adopted a lot of the basic C support).
 
Status
Not open for further replies.
Back
Top