Does the Main.main function need special treatment?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Does the Main.main function need special treatment?

BigBang
Is there anything that needs to be taken into account when compiling the Main.main function from Jack code to VM code?

For example, do certain arguments, local variables or anything else need to be declared, or anything else that are not declared in other functions?
Reply | Threaded
Open this post in threaded view
|

Re: Does the Main.main function need special treatment?

WBahn
Administrator
If there were, the authors would have taken care to point it out.

Main.main is just a function, like any other function. It is compiled and translated just like any other function.

The difference come in at the operating system level. One of the OS libraries is the Sys library and it has a function called Sys.init(). This function does some initialization stuff and then calls Main.main().

This is why your main() function has to have that name and be in that class.

The same is true, and for the same reasons, with many programming languages, such as C. There has to be exactly one function named main() because the start up code is hardwired to call that specific function.