Calculation in const statement?

Is it "illegal" in C++ to have a statement like this

const unsigned long sendInterval PROGMEM = 1 * 60 * 1000;

I had this in my program and when examining sendInterval in Visual Studio the value was shown as "60000UL". I had an "if statement" which was never executing so I sent the value of sendInterval to the Serial Monitor and it was a crazy number, well over 13 billion!

I used the calculation "style" originally since it was convenient to indicate that I wanted a time interval of 1 minute which was easily changed to any number of minutes by changing the leading 1. Replacing the calculation with the string "60000" worked.

Is it "illegal" in C++ to have a statement like this

Wouldn't it have been faster to fire up the IDE and try to compile something?

Replacing the calculation with the string "60000" worked.

Because 1, 60, and 1000 are ints, the calculation is done using int registers. Can you say overflow.

60000 is a literal that doesn't fit in an int, so a long register is used to hold the value to be loaded into the variable's memory location.

The best approach, though, is:

const unsigned long sendInterval PROGMEM = 1UL * 60UL * 1000UL;

The UL suffix tells the compiler to use long registers to perform the arithmetic.

That's just fine. The PROGMEM is a bit overkill but you can do a calculation. Only thing is, by default the compiler sees ever constant as a int. So when it sees 1 * 60 * 1000; it will just reserve a int to do the math. So try

const unsigned long sendInterval PROGMEM = 1UL * 60 * 1000;

Only thing is, by default the compiler sees ever constant as a int.

Every constant [u]that can be interpreted as an int[/u] IS interpreted as an int. 60000 can't be, so it is seen as a long.

Devil is in the detail ;) Thanks Paul :)