Answer the question
In order to leave comments, you need to log in
What is the main method for?
hello! I still can't understand the essence of the main method. Everywhere it is written they say the program starts exactly from the class where there is a main method and in it (the body of the main method) the code is written that will be executed. Is it not the user who determines the order by his actions, decides which methods and variables, etc.? will be used depending on his requirement ? then how can you describe in advance the methods that will be executed in the main method? And if I misunderstood the essence of the lane method, please help me understand why the lane method is needed and what does it generally define in its body?
Answer the question
In order to leave comments, you need to log in
There is a piece of system code in the operating system whose purpose is to "Start the program to be executed". When you hit the exe file twice, this part creates a process, creates a primary thread, maps chunks of data from your exe file to memory regions into the process, and other equally important processes.
When the system loader wants to find and transfer control to the primary thread, it must answer the question "Where can I find the machine code for the primary thread?". He, the sys.loader, knows how the exe file format is arranged and finds the value of the pointer where the code is located, from where the program written in the exe file should start working. For exe files, see the winnt.h header in the IMAGE_OPTIONAL_HEADER field of AddressOfEntryPoint.
Every modern executable typically has two entry points. One of them is nothing more than "start code", sometimes referred to as runtime-code or "stub". This part is generated by the compiler and is repeated quite often for all files generated by the compiler. And the other part is "custom", this is the user and there is your main (). But its name can be configured differently (see the documentation for your compiler).
That runtime code, that your main() is nothing but callback functions. They are called by the sys.loader itself. After the runtime code is written to the file, a pointer to it is written to the AddressOfEntryPoint (see above), while working in the bowels of the generated runtime code, there is a transition to your main ().
The essence of main is the entry point. The program must "start" its execution from somewhere. When the system starts your application, it calls main. I can't figure out what's wrong.
In the program, you need to determine the place where it starts, in other words, the entry point. It was accepted by the language developers that the procedure/method named main is launched first in the program, i.e. main is the convention. The name main has been fixed historically, in some languages the entry points to the program have other names and even a different form, i.e. are not a procedure/method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question