Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12610 Discussions

What is the difference between main() and alt_main()?

Altera_Forum
Honored Contributor II
1,029 Views

I write a very simple program, driving LED through PIO. Both function can work. If using main() , the code size is 1940 bytes. If alt_main(), the code size is 472 bytes. It seems that main() include some initialization. 

 

Can anyone explain the difference, or recommend some documents to read? Thanks.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
277 Views

Actually it is the default alt_main() that contains the extra code - either side of the call to main(). 

Largely this is code for initialising stdio for printf() - which pulls in a lot of 

library code.
0 Kudos
Altera_Forum
Honored Contributor II
277 Views

Hi sabertooth 

 

I copy here the comment to alt_main() definition 

 

/* 

* alt_main is the C entry point for the HAL. It is called by the assembler 

* startup code in the processor specific crt0.S. It is responsible for: 

* completing the C runtime configuration; configuring all the 

* devices/filesystems/components in the system; and call the entry point for 

* the users application, i.e. main(). 

*/ 

 

 

Regards
0 Kudos
Altera_Forum
Honored Contributor II
277 Views

Many thanks to Cris72.

0 Kudos
Reply