开发者

Origins of the name 'main' for program entry point?

开发者 https://www.devze.com 2022-12-28 04:41 出处:网络
Out of curiosity, what are 开发者_JAVA技巧the origins of the name \'main\' for a program entry point?Before C, there was IBM\'s PL/I.In PL/I you declared a procedure with options.If you wrote

Out of curiosity, what are 开发者_JAVA技巧the origins of the name 'main' for a program entry point?


Before C, there was IBM's PL/I. In PL/I you declared a procedure with options. If you wrote

PROC MUMBLE OPTIONS(MAIN);

that told the compiler that the MUMBLE procedure was the main procedure. PL/I may have adopted this convention from elsewhere, or C may have adopted it from PL/I, or maybe it was just in the air. But it definitely predates C.

(If anyone is wondering why all upper case, the IBM keypunches of the day did not support lower-case characters. Yes, I wrote programs on punched cards. That's probably why I'm a bit shaky on the syntax; it has been a while.)


I'm pretty sure that it has to do with the fact that it is the 'main' function of the program. Anything more than that is unknown to me.


In Fortran the main program was the main program even though it didn't have a name. It was distinguished from subroutines and functions by having an executable statement (or other non-commentary statement) without a preceding SUBROUTINE or FUNCTION statement.

When later languages decided they wanted the main routine to start with a beginning line like other procedures or functions, some of them adopted the word MAIN or main in various ways.

As someone else pointed out, Pascal did it differently. Shell scripts and Perl resemble Fortran.


My understanding (though I couldn't find a reference to confirm) is that some early languages had a notion of a main procedure (the first might have been Ada), even though you did not have to name it main().

I think that C was the first language to actually use this token as a name. C largely replaced Pascal which didn't have a named start procedure, if I remember correctly.

From there it influenced subsequent languages that were C inspired like C++, Java and C#.

It also influenced culturally languages that do not mandate such a function, like Python.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号