Why does #define not multiply numbers as expected in arduino/c++?

  arduino, arduino-ide, c++

Arduino has been giving me unexpected values when trying to multiply numbers together in preprocessor.

e.g.

#define msPerDay (24 * 60 * 60 * 1000)
void setup() {
    Serial.begin(9600);
    Serial.println(msPerDay);
}
void loop() {}

This should output 86400000 but instead I get

23552

In the serial monitor. Also

#define msPerDay (60 * 1000)
void setup() {
    Serial.begin(9600);
    Serial.println(msPerDay);
}
void loop() {}

Should output 60000 but instead prints

-5536

Why is this giving me these unexpected values, what are the rules C++ uses to calculate #define multiplications?

Source: Windows Questions C++

LEAVE A COMMENT