简体   繁体   中英

Need of main function in C, used in microcontrollers

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM