The need for a basic function in C used in microcontrollers

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

When the microcontroller loads, the control first reaches the reset handler, from which the control jumps to whatever function I need. If I don't use the initialization code provided by the compiler library, I can keep calling whichever function I would like. Then why do I need main ()? My IDE (Codewarrior) insists that you have main (). Any ideas?

+3


source to share


1 answer


According to the C99 standards, it is not necessary to have a function main

for a "stand-alone" environment. In microcontrollers, it is common to run the initialization code from the reset vector.This code does global variable initialization, stack initialization, etc. and then proceeds to the function main

.

You can change the location of the launch vector or the launch itself. You can simply decide not to call the main function from your startup code.



If you are using your own startup code, make sure your IDE settings are set correctly to avoid generating startup code.

+2


source







All Articles