[answered] C's main() in Arduino

I know I've seen the main() code that the environment inserts behind the scenes that runs setup() and loop(), before. I wanted to show it to someone to prove that Arduino is "real" C, but I can't find it in my 105r2 install now.

Can someone point me to it please, or even just post it here would be cool...

TIA

https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp

	if (serialEventRun) serialEventRun();

Peter_n: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp

Thanks....

Nick -

Could you please expand a little? I can think of at least three reasons why I might sigh at this line of code, but I don't know your reasons.

main used to look like this:

int main(void)
{
    init();
    setup();
    for (;;) {
        loop();
    }
    return 0;
}

Nice and simple. Basic initialization. Then user initialization (setup) followed by the "loop" paradigm. So far so good.

Then they had to go and add this line:

    if (serialEventRun) serialEventRun();

It's basically polling, and relying on you exiting loop, for serialEventRun() to be called. Plus it is another test every time around the loop. We get queries about "how come serialEventRun wasn't called?". And it turns out the user hoped that it would be called whenever it was required.

I just think it has taken a simple concept and made it confusing.