main() vs. setup() + loop()

What happens in setup() that causes things to work, but when using "int main( void )" nothing happens?

On the Uno, I learned that I needed to explicitly invoke sei() or Serial.print*() wouldn't work. In the SAM3X8E context and code files, I see something called SystemInit() in one file, but that doesn't have much effect either.

Well in the context of the Uno board nothing happens in setup() except what you plug into it. in fact the following example sketch from the IDE is valid and will compile and upload, while doing nothing.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

What you are probably think of is the main() function the IDE 'wraps' you sketch around, as it has an init() function that sets up timer0 and enables it's interrupt so that the millis() function can well..function. :wink:

This is the main function:

int main( void )
{
	init();

	delay(1);

#if defined(USBCON)
	USBDevice.attach();
#endif

	setup();

	for (;;)
	{
		loop();
		if (serialEventRun) serialEventRun();
	}

	return 0;
}