[failed verification][1] To start a program's execution, the loader or operating system passes control to its entry point.
However, in day-to-day software development, programmers specify the entry points only in source code, which makes them much better known.
[5][6] In many major operating systems, the standard executable format has a single entry point.
In the GNU Compiler Collection (gcc), the entry point used by the linker is the _start symbol.
Similarly, in the Portable Executable format, used in Microsoft Windows, the entry point is specified by the AddressOfEntryPoint field, which is inherited from COFF.
Instead, they have essential components (activities and services) which the system can load and run as needed.
[7] An occasionally used technique is the fat binary, which consists of several executables for different targets packaged in a single file.
The usual way to denote entry points, as used system-wide in VMS and in PL/I and MACRO programs, is to append them at the end of the name of the executable image, delimited by a dollar sign ($), e.g. directory.exe$make.
[clarification needed] In general, programs can exit at any time by returning to the operating system or crashing.
However, some languages can execute user-written functions before main runs, such as the constructors of C++ global objects.
A non-exhaustive list of programming languages follows, describing their way of defining the main entry point: In APL, when a workspace is loaded, the contents of "quad LX" (latent expression) variable is interpreted as an APL expression and executed.
Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must always be int;[8] for example, Unix (though not POSIX.1) and Windows have a third argument giving the program's environment, otherwise accessible through getenv in stdlib.h: Darwin-based operating systems, such as macOS, have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:[9] The value returned from the main function becomes the exit status of the process, though the C standard only ascribes specific meaning to two values: EXIT_SUCCESS (traditionally 0) and EXIT_FAILURE.
When executing a program written in C#, the CLR searches for a static method marked with the .entrypoint IL directive, which takes either no arguments, or a single argument of type string[], and has a return type of void or int, and executes it.
For versions of Main() returning an integer, similar to both C and C++, it is passed back to the environment as the exit status of the process.
Since C#7.1 there are four more possible signatures of the entry point, which allow asynchronous execution in the Main() Method.
async is required to allow the use of asynchrony (the await keyword) inside the method.
ANSI Common Lisp does not define a main function; instead, the code is read and evaluated from top to bottom in a source file.
For versions of main() returning an integer, similar to both C and C++, it is passed back to the environment as the exit status of the process.
Dart is a general-purpose programming language that is often used for building web and mobile applications.
Any Dart code that is intended to be executed when the program starts should be included in the main function.
[12] Some versions of Fortran, such as those on the IBM System/360 and successor mainframes, do not support the PROGRAM statement.
Using GNAT, the programmer is not required to write a function named main; a source file containing a single subprogram can be compiled to an executable.
IO is a monad, which organizes side-effects in terms of purely functional code.
Also unlike C, the number of arguments need not be included, since arrays in Java have a field that keeps track of how many elements there are.
Starting from the first line of a PHP script, any code not encapsulated by a function header is executed as soon as it is seen.
Example: Python programs are evaluated top-to-bottom, as is usual in scripting languages: the entry point is the start of the source code.
This can be done by the following idiom, which relies on the internal variable __name__ being set to __main__ when a program is executed, but not when it is imported as a module (in which case it is instead set to the module name); there are many variants of this structure:[19][20][21] In this idiom, the call to the named entry point main is explicit, and the interaction with the operating system (receiving the arguments, calling system exit) are done explicitly by library calls, which are ultimately handled by the Python runtime.
When run in an Xcode Playground,[24] Swift behaves like a scripting language, executing statements from top to bottom; top-level code is allowed.Cocoa- and Cocoa Touch-based applications written in Swift are usually initialized with the @NSApplicationMain and @UIApplicationMain attributes, respectively.
Those attributes are equivalent in their purpose to the main.m file in Objective-C projects: they implicitly declare the main function that calls UIApplicationMain(_:_:_:_:)[25] which creates an instance of UIApplication.
[26] The following code is the default way to initialize a Cocoa Touch-based iOS app and declare its application delegate.In Visual Basic, when a project contains no forms, the startup object may be the Main() procedure.
Main
()
might look in
C#
source code. Different parts are labeled for reference.