I was surprised not to see at least a warning on the small test program below. I have written a function called MySquare() that squares an integer number:
int MySquare(int n)
{
if (n < 182) // 182 overflows a 16-bit int
return n * n;
else
return -1;
}
void setup() {
int num = 181;
float val = 181.0;
Serial.begin(9600);
num = MySquare(num);
Serial.println(num);
// val = MySquare(val);
// Serial.println(val);
}
void loop() {
}
The code works as expected on the int function argument, but also works correctly on the (currently comment-out) float data, too. The print statement shows the default two decimal places on the float version. I would have expected some kind of type-checking error, but get none. I'm using 1.8.10 on an Arduino Mega2560, Win 10.