Global variable initialization with expression or not, inconsistent behaviour

Hello I would like to ask the community why is this behavior happening regarding initialization of global variables with mathematics expressions, or if it is some kind of detail i am missing, even though i am fairly sure i am not.

The replication is really easy. Below are 2 equivalent source codes but the one with an expression to be calculated at compile time results in undefined behavior

The not working example:

unsigned long REFRESH_MSEC = 60*60*1000; // 1 hour -->3600000 which is less than 2^32
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(REFRESH_MSEC);
}

And the working example:

unsigned long REFRESH_MSEC = 3600000; // 1 hour resfresh if possible
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(REFRESH_MSEC);
}

I have not tried other means of replication. If you confirm the results i will proceed with further testing. This has given me half day head ache alreadt Thanks in advance

Not sure if println support long type, probably the second variant is working simply because compiler or optimizer made a casting to integer, which isn't happened with first example where variable is considered to be not define at compiling time.

I do not agree with you as it would have been spotted already and the documentation for the unsigned long type has an example of its use with Serial.println here http://www.arduino.cc/en/Reference/UnsignedLong.

unsigned long REFRESH_MSEC = 60*60*1000; // 1 hour -->3600000 which is less than 2^32

60 is an "int", as is "1000"

60 * 60 * 1000 = 0x36EE80, 0xEE80 = -4480

unsigned long REFRESH_MSEC = 60UL*60UL*1000UL; // 1 hour -->3600000 which is less than 2^32

is the correct way of writing this.

Wow, i did not try but you are absolutely correct. I think i would have not came up with it although i know literals are implicitly int's. Thanks a lot. May others have it as an example. Maybe the reference could be update so others don't fall in this detail.