I wrote a sketch that used the millis()
function in several places. I got odd behavior because I inadvertently used the plain millis
in one line, without the parens. It evaluated to zero when running.
Why didn't the compiler flag this as an undeclared variable? I suspect it's because the name was already in the symbol table, but I still would have thought it'd be caught. Is this a quirk, or expected? If expected, what is the benefit?
C/C++ is not my main language so be gentle. (-:
Edit as requested to show some code. This is an incomplete sample, but shows the usage:
const unsigned long GATE_OPEN_TIMER = 7000;
const unsigned long GATE_CLOSE_TIMER = 12000;
...
unsigned long gateStopTime = 0;
...
if (isGateCycling) { // if open/close cycle is running
if (isGatePassive) { // if we're not applying power
if (millis() >= gateStopTime) { // if current delay expired
digitalWrite(GateCloseRelay, ACTIVE);
gateStopTime = millis() + GATE_CLOSE_TIMER;
isGatePassive = false;
... followed by similar logic for the reverse direction. If any use of millis()
is replaced by millis
, the code falls over but the compiler sees nothing wrong.