Timeline for Sketch does not work without delay() or other complex functions like digitalWrite()
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 20, 2016 at 21:25 | vote | accept | user2882440 | ||
Aug 20, 2016 at 14:17 | comment | added | Majenko | As long as the result of the count is used somewhere (and that "somewhere" doesn't get optimized out) the count will never be optimized, under any circumstances. Such behaviour would break massive amounts of code all over the place. I reiterate: it cannot happen. Ever. Full stop. I suspect your "it happened to me" was something completely different. You may have seen it optimized out as a casualty of something else being optimised out (such as an empty if that gets optimized out) but as long as there is something using the count it CANNOT be optimized out. Counting is perfectly reliable. | |
Aug 20, 2016 at 14:13 | comment | added | jantje | As I said, It happened to me. I never stated it would happen. As Arduino now is plenty of toolchains and cores I think it is save to say: I could happen. Maybe you should reread my answer. | |
Aug 20, 2016 at 13:50 | comment | added | Majenko |
What makes you think the optimizer would ever do something as idiotic as that? (By the way: try it for your self. Compile the code without delay() and look at the assembly output. You'll see the count never gets optimized out). The only time the optimizer would remove the counting is if the result of the counting does nothing (i.e., if the if is empty).
|
|
Aug 20, 2016 at 13:44 | comment | added | jantje | because loop() is actually in a while(true) loop. So without the delay you get while(true){count++;if(count==316){[something]}}. Which can get optimized to while(true){[something]}. I have had that happen to me. | |
Aug 20, 2016 at 13:39 | comment | added | Majenko | Why do you think that removing a function that has no relationship at all with the counting would affect how the compiler optimizes the counting? | |
Aug 20, 2016 at 13:38 | comment | added | jantje | You are right when delay is there. I mean when delay is gone. | |
Aug 20, 2016 at 12:56 | comment | added | Majenko | There is absolutely no reason for the optimizer to remove the counting. If it did that sort of thing then nothing would ever work. The compiler has no clue what delay() does. | |
Aug 20, 2016 at 12:19 | history | answered | jantje | CC BY-SA 3.0 |