I want to know, do only compiler based languages use a entry point, or if a interpreter based language can also use entry points, if yes then please give 1 example.
CodePudding user response:
I shell scripts starts at the beginning of the script file. A python program starts at the beginning of the python file. In both cases you can call that the "entry" point.
The decision, if a program starts at the beginning of the file (like in both the examples above) or starts at a specific function (like main
) has nothing to do with the decision to make a language compiled or interpreted. It is a mere language design consideration.
Addition
It is actually a quite common for example in python to do something like
# include statements and
# class definitions and
# function definitions go here
def main():
pass
#do main stuff here
if __name__ == "__main__":
main()
This defines a main function and the first non-definition statement calls it, if the module is the main program file.
CodePudding user response:
A typical way a program is started in Linux is by a shell calling fork execve. The new process is loaded and begins execution at the entry point specified by the format of the executable; for example ELF. In the case of an interpreted language, the executable is the interpreter specified on the first line after #! such as /usr/bin/python.