Need of main function in C, used in microcontrollers

645 views Asked by At

I have been using C for embedded systems for a while, but I have a question regarding the main() function.

When a microcontroller boots up, the control first reaches the reset handler, from where the control goes to whichever function I need to. If I am not using the initialization code provided by the compiler library, I can keep calling whichever function I would like to. Then, why do I need main()? My IDE (Codewarrior) insists on having main() though. Any ideas?

1

There are 1 answers

1
Vagish On BEST ANSWER

As per C99 standards it is not mandatory to have main function for 'freestanding' environment. In micro-controllers generally start-up initialization code is called from reset vector.This code performs Global variable initialization,stack initialization etc. and then jumps to main function.

You can modify the start-up vector location OR start-up code itself. You can simply decide to not call main function from start-up code.

If you are using your own start-up code please make sure your IDE settings are properly set to not generate start-up code.