The C++ standard provides for two execution environments: freestanding and hosted. Most folks here run in a hosted environment, where your program starts inmain()
. Embedded systems run in a freestanding environment, where program startup is through an implementation-defined mechanism. Compilers for a freestanding environment are allowed to leave out some parts of the standard library. For more details, see here.
So, setup()
and loop()
are okay in a freestanding environment. No main()
required. I don’t know if the library for Arduino meets the requirements in the standard.
In a hosted environment, there’s typically an operating system (the host) that lets you launch programs. C++ programs for such an environment must have main()
. In a freestanding environment, the program typically starts when the device is turned on. That’s much closer to the metal, and the system is allowed to have its own requirements, in order simplify the boilerplate code that fires off the application.