Skip to content

Instantly share code, notes, and snippets.

@daoleno
Created May 14, 2018 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daoleno/a5155260304116f15405461a7b0d7f60 to your computer and use it in GitHub Desktop.
Save daoleno/a5155260304116f15405461a7b0d7f60 to your computer and use it in GitHub Desktop.
What happens before main() function is executed in C.
  • The hardware is initialized. The most important part of this step is setting up the clock that the CPU needs to run the code. This is usually done by programming a PLL (essentially a programmable clock). If there is not clock going to the CPU, the CPU is essentially dead. The other part of hardware initialization is initializing the interrupt handling hardware.
  • Memory segments are initialized. Memory segments such as .bss (for uninitialized data), .data (for initialized data such as static variables, global variables, local static variables, addresses of functions, and function pointers), and .text (where the actual code resides) are initialized and a valid stack is set up.
  • Command line arguments are received. This may not be relevant in embedded systems as in embedded systems we don’t usually call main() with arguments
  • The stack pointer is configured. This is necessary because the program needs to know where to start from.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment