I've made up a test case:
const unsigned long GATE_OPEN_TIMER = 7000;
const unsigned long GATE_CLOSE_TIMER = 12000;
unsigned long gateStopTime = 0;
void setup()
{
if (millis >= gateStopTime) { // if current delay expired
gateStopTime = millis + GATE_CLOSE_TIMER;
}
}
void loop()
{
}
Under IDE 1.6.9 I get these errors:
/tmp/arduino_modified_sketch_345879/sketch_oct27a.ino: In function 'void setup()':
sketch_oct27a:7: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (millis >= gateStopTime) { // if current delay expired
^
/tmp/arduino_modified_sketch_345879/sketch_oct27a.ino:8:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
gateStopTime = millis + GATE_CLOSE_TIMER;
^
sketch_oct27a:8: error: invalid conversion from 'long unsigned int (*)()' to 'long unsigned int' [-fpermissive]
gateStopTime = millis + GATE_CLOSE_TIMER;
^
exit status 1
ISO C++ forbids comparison between pointer and integer [-fpermissive]
Under IDE 1.6.12 they are downgraded to warnings:
/tmp/untitled109152362.tmp/sketch_oct25b/sketch_oct25b.ino: In function 'void setup()':
/tmp/untitled109152362.tmp/sketch_oct25b/sketch_oct25b.ino:9:21: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (millis >= gateStopTime) { // if current delay expired
^
/tmp/untitled109152362.tmp/sketch_oct25b/sketch_oct25b.ino:10:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
gateStopTime = millis + GATE_CLOSE_TIMER;
^
/tmp/untitled109152362.tmp/sketch_oct25b/sketch_oct25b.ino:10:31: warning: invalid conversion from 'long unsigned int (*)()' to 'long unsigned int' [-fpermissive]
gateStopTime = millis + GATE_CLOSE_TIMER;
^
Sketch uses 512 bytes (1%) of program storage space. Maximum is 32,256 bytes.
Global variables use 13 bytes (0%) of dynamic memory, leaving 2,035 bytes for local variables. Maximum is 2,048 bytes.
So, the compiler isn't totally letting you get away with it. You should check the warnings. But why are the warnings only warnings?
Checking the generated compile command (using verbose compiling) I see that 1.6.12 has an extra option: -fpermissive
.
From the documentation:
Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive allows some nonconforming code to compile.
So you have "nonconformant code" but you are getting away with it.
I don't know why the Arduino devs did that. The whole point of making things like that errors is so you fix them at compile time, rather than scratching your head about why things don't work at run time.
Clearly the symbol millis
exists. But it is a function (or perhaps a pointer to a function) and thus shouldn't be just compared to a number or have a number added to it. That's what those errors were about in 1.6.9.
Just remember, in C, C++ and the ilk, to call a function you always use parentheses, even if you are passing no arguments.
millis
- can you post the code? A line like this generates a compiler error:int foo = millis;
The error isinvalid conversion from 'long unsigned int (*)()' to 'long unsigned int'
future = millis() + delay
followed later byif millis >= future
Ctrl+K
to have your browser do this for you. Thatif
statement doesn't look valid anyway.future
?