So what does exit(0) actually do
This is from the documentation...
In a C++ context, global destructors will be called before halting execution.
I have not tested "in a C++ context" so I don't know if destructors are in fact called. In my test Sketch, this is essentially what was produced...
void exit( int ignored )
{
cli();
while ( true );
}
and what command puts the processor to sleep?
This should do the trick (untested)...
#include <avr/sleep.h>
void die( void )
{
set_sleep_mode( SLEEP_MODE_PWR_DOWN );
while ( true )
{
sleep_enable();
cli();
sleep_cpu();
}
}
The "while ( true )" should not be necessary but I've dealt with enough "should nots" in my life to know that including it is worth the two (or four) bytes of Flash.