While coding I got into this weird situation, where my code just wouldn't work as it should. I even made it in Visual Studio in C#, and there, the same logic worked just fine. After some testing, I got to this simple code, that don't work as it should. Test it and see it:
void setup() {
Serial.begin(9600);
}
void loop() {
int arr[] = {32768};
if (1 > arr[0])
{
Serial.println("1 is greater than 32768");
}
else
{
Serial.println("1 is not greater");
}
delay(1000);
}
Any time I try to make a comparison with a value in an array bigger than 327698 (which is the maximum number for 2 bytes) things don't happen as they should.
Appreciate any enlightening.
It is actually not a limitation, just a choice made by the developers of Arduino, and specific to AVR based Arduinos.
The size of an int variable is not specified by the C/C++ programming language. If you want your program to operate as expected on other MCUs, determine the size of an int using the sizeof operator. For example: