Go Down

Topic: Never returning for loop()? (Read 1 time) previous topic - next topic


New to Arduino, but pretty experienced coder.  The idea of the Arduino calling loop() repeatedly looks a lot like cooperative multitasking (ala Win3.1 and early MacOS).  So my question is this: if loop() calls a function that never returns, what do I lose?  I assume there is some housekeeping going in the "background". For example:

void setup(){
  // some stuff

void loop(){

void goawayforever(){
    //do some stuff;

I have looked for the source code that runs in the Arduino but have been stymied.  



Sep 25, 2010, 04:29 pm Last Edit: Sep 25, 2010, 04:32 pm by Korman Reason: 1

your thoughts are too complicated, it's far more primitive than that. Look into arduino/hardware/arduino/cores/arduino/main.cpp and you'll see this:
Code: [Select]
int main(void)
       for (;;)
       return 0;

This should answer all your questions.



Also, it would not need co-operative multitasking (which is not so difficult on theArduino), but pre-emptive multitasking.

However there is an implementation of a FreeRTOS (DuinOS)


   Indeed, I was overthinking...thanks for the concise answer!

Andy Brown

The only stuff going on in the background is the interrupt service routine that keeps track of clock ticks. You can see that in wiring.c. Everything else that happens is because you made it so, whether you meant to or not  ;)
Home of the Nokia QVGA TFT LCD hacks: http://andybrown.me.uk

Go Up