Why the function name main() is retained in many languages like C, C++, Java? Why not any other names for that function? Is there any common structure for all these 3 main() (in C, C++, Java)
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Multiple sockets for clients to connect to
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Or, to be more obtuse, Why do we drive on the side of the road we do?
Answer: We had to choose something.
It's not always main().
Java Applets use init() and start() for the external caller to hook into.
Servlets are started via init() and service() methods.
(service will dispatch to the more familiar doGet and doPost methods)
Granted, these exceptions do rely on some container other than the OS to invoke the methods.
If you develop an embedded system, you may see other names.
ECos uses
(or main(), depending on the setup).
A linux kernel module uses a function marked with __init (though that's not the same thing, since modules are event-driven, typically).
The language designers had to choose "some" name and main() sounds like the Main function, since that is where the execution starts :)
How would you name the main function of a program?
There are a lot of silly and not very respectful answers here to a legitimate question.
C didn't come from nowhere. Its immediate ancestor is B, written by Ken Thompson. Here is a link to the B manual. The basic structure of a B program is
main(); exit();
main() is provided by the programmer and exit() is supplied by the library. This seems to be the first appearance of main() as the predecessor of B, BCPL, has no such concept. I guess you would have to ask Ken Thompson why it was main and not something else.