简体   繁体   English

程序入口点名称“ main”的由来?

[英]Origins of the name 'main' for program entry point?

出于好奇,程序入口点名称“ main”的来历是什么?

Before C, there was IBM's PL/I. 在C之前,有IBM的PL / I。 In PL/I you declared a procedure with options. 在PL / I中,您声明了带有选项的过程。 If you wrote 如果你写

PROC MUMBLE OPTIONS(MAIN);

that told the compiler that the MUMBLE procedure was the main procedure. 告诉编译器MUMBLE过程是主要过程。 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. PL / I可能从其他地方采用了该约定,或者C可能从PL / I中采用了该约定,或者可能只是在发布。 But it definitely predates C. 但这肯定早于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.) (如果有人想知道为什么所有的大写字母都没有,今天的IBM按键不支持小写字符。是的,我在打孔卡上编写了程序。这可能就是为什么我在语法上有些动摇;它一直是而。)

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. 在Fortran中,即使没有名称,主程序也是主程序。 It was distinguished from subroutines and functions by having an executable statement (or other non-commentary statement) without a preceding SUBROUTINE or FUNCTION statement. 它与子例程和函数的区别在于,它具有一个可执行语句(或其他非注释语句),而没有前面的SUBROUTINE或FUNCTION语句。

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. 当后来的语言决定他们希望主例程像其他过程或函数一样从起始行开始时,其中的一些便以各种方式采用了“ MAIN”或“ main”一词。

As someone else pointed out, Pascal did it differently. 正如其他人指出的那样,帕斯卡的做法有所不同。 Shell scripts and Perl resemble Fortran. Shell脚本和Perl类似于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(). 我的理解(尽管找不到参考文献来确认)是,即使您不必将其命名为main(),某些早期语言也具有主过程的概念(第一个可能是Ada)。

I think that C was the first language to actually use this token as a name. 我认为C是第一种实际使用此标记作为名称的语言。 C largely replaced Pascal which didn't have a named start procedure, if I remember correctly. 如果我没记错的话,C在很大程度上取代了没有指定启动过程的Pascal。

From there it influenced subsequent languages that were C inspired like C++, Java and C#. 从那里开始,它影响了后来受到C语言启发的语言,例如C ++,Java和C#。

It also influenced culturally languages that do not mandate such a function, like Python. 它还影响了没有强制执行此功能的语言,例如Python。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM