In computer programming , an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
59-438: To start a program's execution , the loader or operating system passes control to its entry point. (During booting , the operating system itself is the program). This marks the transition from load time (and dynamic link time , if present) to run time . For some operating systems and programming languages , the entry point is in a runtime library , a set of support functions for the language. The library code initializes
118-463: A computer or virtual machine interprets and acts on the instructions of a computer program . Each instruction of a program is a description of a particular action which must be carried out, in order for a specific problem to be solved. Execution involves repeatedly following a " fetch–decode–execute " cycle for each instruction done by the control unit . As the executing machine follows the instructions, specific effects are produced in accordance with
177-560: A dollar sign ($ ), e.g. directory.exe$ make . The Apple I computer also used this to some degree. For example, an alternative entry point in Apple I's BASIC would keep the BASIC program useful when the reset button was accidentally pushed. In general, programs can exit at any time by returning to the operating system or crashing . Programs in interpreted languages return control to the interpreter, but programs in compiled languages must return to
236-519: A member function , although the name is not otherwise reserved, and may be used for member functions, classes, enumerations, or non-member functions in other namespaces. In C++ (unlike C) main() cannot be called recursively and cannot have its address taken. 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
295-406: A distance is valid only if all elements of the object are of the same size (typically given in bytes or words ). For example, if A is an array of characters containing "abcdef" , the fourth element containing the character 'd' has an offset of three from the start of A . In computer engineering and low-level programming (such as assembly language ), an offset usually denotes
354-411: A fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary: 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 . The meaning of other possible return values is implementation-defined. In case a return value
413-453: A memory location in the format of segment:offset. For example, assume we want to refer to memory location 0xF867. One way this can be accomplished is by first defining a segment with beginning address 0xF000, and then defining an offset of 0x0867. Further, we are also allowed to shift the hexadecimal segment to reach the final absolute memory address. One thing to note here is that we can reach our final absolute address in many ways. An offset
472-411: A more descriptive argv[0] , usually by means of the exec system call. The main() function is special; normally every C and C++ program must define it exactly once. If declared, main() must be declared as if it has external linkage; it cannot be declared static or inline . In C++, main() must be in the global namespace (i.e. ::main ), cannot be overloaded, and cannot be
531-455: A program can begin at a named point, either with a conventional name defined by the programming language or operating system or at a caller-specified name. In many C-family languages , this is a function called main ; as a result, the entry point is often known as the main function . In JVM languages , such as Java , the entry point is a static method called main ; in CLI languages such as C#
590-582: A program from direct manipulation of the computer peripherals, providing more general, abstract services instead. In order for programs and interrupt handlers to work without interference and share the same hardware memory and access to the I/O system, in a multitasking operating system running on a digital system with a single CPU/MCU, it is required to have some sort of software and hardware facilities to keep track of an executing process's data (memory page addresses, registers etc.) and to save and recover them back to
649-470: A program is to be executed, a loader first performs the necessary memory setup and links the program with any dynamically linked libraries it needs, and then the execution begins starting from the program's entry point . In some cases, a language or implementation will have these tasks done by the language runtime instead, though this is unusual in mainstream languages on common consumer operating systems. Some program debugging can only be performed (or
SECTION 10
#1732863247777708-494: A range of between 0 and 4096 bytes. For example, within an unconditional branch instruction (X'47F0Fxxx'), the xxx 12-bit hexadecimal offset provided the byte offset from the base register (15) to branch to. An odd offset would cause a program check (unless the base register itself also contained an odd address)—since instructions had to be aligned on half-word boundaries to execute without a program or hardware interrupt . The previous example describes an indirect way to address to
767-452: A set variety of actions using a single program. In most of today's popular programming languages and operating systems, a computer program usually only has a single entry point . In C , C++ , D , Zig , Rust and Kotlin programs this is a function named main ; in Java it is a static method named main (although the class must be specified at the invocation time), and in C# it
826-516: A simple main function in Dart: In this example, the main function simply prints the text Hello, world! to the console when the program is run. This code will be executed automatically when the Dart program is run. It is important to note that while the main function is the default entry point for a Dart program, it is possible to specify a different entry point if needed. This can be done using
885-495: A single argument of type string[] , and has a return type of void or int , and executes it. Command-line arguments are passed in args , similar to how it is done in Java. 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
944-523: Is a list of instructions and data to cause a computer "to perform indicated tasks according to encoded instructions ", as opposed to a data file that must be interpreted ( parsed ) by a program to be meaningful. The exact interpretation depends upon the use. "Instructions" is traditionally taken to mean machine code instructions for a physical CPU . In some contexts, a file containing scripting instructions (such as bytecode ) may also be considered executable. The context in which execution takes place
1003-626: Is a static method named Main . In many major operating systems, the standard executable format has a single entry point. In the Executable and Linkable Format (ELF), used in Unix and Unix-like systems such as Linux , the entry point is specified in the e_entry field of the ELF header. In the GNU Compiler Collection (gcc), the entry point used by the linker is the _start symbol. Similarly, in
1062-426: Is crucial. Very few programs execute on a bare machine . Programs usually contain implicit and explicit assumptions about resources available at the time of execution. Most programs execute within multitasking operating system and run-time libraries specific to the source language that provide crucial services not supplied directly by the computer itself. This supportive environment, for instance, usually decouples
1121-637: Is ever executed. Type checking , register allocation , code generation , and code optimization are typically done at compile time, but may be done at runtime depending on the particular language and compiler. Many other runtime errors exist and are handled differently by different programming languages , such as division by zero errors, domain errors, array subscript out of bounds errors, arithmetic underflow errors, several types of underflow and overflow errors, and many other runtime errors generally considered as software bugs which may or may not be caught and handled by any particular computer language. When
1180-683: Is executed. A virtual machine ( VM ) is the virtualization / emulation of a computer system . Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardware, software, or a combination. Virtual machines differ and are organized by their function, shown here: Some virtual machine emulators, such as QEMU and video game console emulators , are designed to also emulate (or "virtually imitate") different system architectures thus allowing execution of software applications and operating systems written for another CPU or architecture. OS-level virtualization allows
1239-419: Is generally the first programmer-written function that runs when a program starts, and is invoked directly from the system-specific initialization contained in the runtime environment ( crt0 or equivalent). However, some languages can execute user-written functions before main runs, such as the constructors of C++ global objects. In other languages, notably many interpreted languages , execution begins at
SECTION 20
#17328632477771298-447: Is greater than 0; if a user types a command of " rm file ", the shell will initialise the rm process with argc = 2 and argv = {"rm", "file", NULL} . As argv[0] is the name that processes appear under in ps , top etc., some programs, such as daemons or those running within an interpreter or virtual machine (where argv[0] would be the name of the host executable), may choose to alter their argv to give
1357-399: Is implemented independent of the source code, by attaching a special software product to the runtime engine. A runtime system , also called runtime environment , primarily implements portions of an execution model . This is not to be confused with the runtime lifecycle phase of a program, during which the runtime system is in operation. When treating the runtime system as distinct from
1416-470: Is itself then run in the aforementioned runtime system . Most programming languages have some form of runtime system that provides an environment in which programs run. This environment may address a number of issues including the management of application memory , how the program accesses variables , mechanisms for passing parameters between procedures , interfacing with the operating system , and otherwise. The compiler makes assumptions depending on
1475-408: Is more efficient or accurate when performed) at runtime. Logic errors and array bounds checking are examples. For this reason, some programming bugs are not discovered until the program is tested in a production environment with real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end-user may encounter a "runtime error" message. Exception handling
1534-481: Is not always relative to the base address of the module, for example: If you have a class and you want to retrieve the "color" attribute of this class, the offset may be 0x0100, but this offset has to be added to the offset of the class itself, not the base address. If the class' offset is 0xFF881 and the base address is 0x0A100, then to retrieve the "color" attribute both offsets are added to the base address. 0x0A100 (base) + 0xFF881 (class) + 0x0100 (attribute). Ultimately
1593-452: Is not defined by the programmer, an implicit return 0; at the end of the main() function is inserted by the compiler; this behavior is required by the C++ standard. It is guaranteed that argc is non-negative and that argv[argc] is a null pointer . By convention, the command-line arguments specified by argc and argv include the name of the program as the first element if argc
1652-459: Is not required to write a function named main ; a source file containing a single subprogram can be compiled to an executable. The binder will however create a package ada_main , which will contain and export a C-style main function. In Go programming language, program execution starts with the main function of the package main There is no way to access arguments or a return code outside of
1711-418: Is one language feature designed to handle runtime errors, providing a structured way to catch completely unexpected situations as well as predictable errors or unusual results without the amount of inline error checking required of languages without it. More recent advancements in runtime engines enable automated exception handling which provides "root-cause" debug information for every exception of interest and
1770-402: Is the final phase of a computer program ' s life cycle , in which the code is being executed on the computer's central processing unit (CPU) as machine code . In other words, "runtime" is the running phase of a program. A runtime error is detected after or during the execution (running state) of a program, whereas a compile-time error is detected by the compiler before the program
1829-524: Is then selected by the operating system. Historically, and in some contemporary legacy systems , such as VMS and OS/400 , computer programs have a multitude of entry points , each corresponding to the different functionalities of the program. 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
Entry point - Misplaced Pages Continue
1888-449: The @pragma("vm:entry-point") annotation in Dart. However, in most cases, the main function is the entry point that should be used for Dart programs. FORTRAN does not have a main subroutine or function. Instead a PROGRAM statement as the first line can be used to specify that a program unit is a main program, as shown below. The PROGRAM statement cannot be used for recursive calls. Some versions of Fortran, such as those on
1947-470: The Main() Method. The Task and Task<int> types are the asynchronous equivalents of void and int . async is required to allow the use of asynchrony (the await keyword) inside the method. Clean is a functional programming language based on graph rewriting. The initial node is named Start and is of type *World -> *World if it changes the world or some fixed type if
2006-557: The IBM System/360 and successor mainframes, do not support the PROGRAM statement. Many compilers from other software manufacturers will allow a fortran program to be compiled without a PROGRAM statement. In these cases, whatever module that has any non-comment statement where no SUBROUTINE, FUNCTION or BLOCK DATA statement occurs, is considered to be the Main program. Using GNAT , the programmer
2065-658: The Portable Executable format, used in Microsoft Windows , the entry point is specified by the AddressOfEntryPoint field, which is inherited from COFF . In COM files , the entry point is at the fixed offset of 0100h. One exception to the single-entry-point paradigm is Android . Android applications do not have a single entry point – there is no special main function. Instead, they have essential components (activities and services) which
2124-494: The central processing unit (CPU) follows from boot-up until the computer has shut down in order to process instructions. It is composed of three main stages: the fetch stage, the decode stage, and the execute stage. In simpler CPUs, the instruction cycle is executed sequentially, each instruction being processed before the next one is started. In most modern CPUs, the instruction cycles are instead executed concurrently , and often in parallel , through an instruction pipeline :
2183-472: The entry point of the program; all these steps depend on the Application Binary Interface of the operating system. At this point execution begins and the program enters run time . The program then runs until it ends, either in a normal termination or a crash . Executable code , an executable file , or an executable program , sometimes simply referred to as an executable or binary ,
2242-402: The runtime environment (RTE), the first may be defined as a specific part of the application software (IDE) used for programming , a piece of software that provides the programmer a more convenient environment for running programs during their production ( testing and similar), while the second (RTE) would be the very instance of an execution model being applied to the developed program which
2301-417: The semantics of those instructions. Programs for a computer may be executed in a batch process without human interaction or a user may type commands in an interactive session of an interpreter . In this case, the "commands" are simply program instructions, whose execution is chained together. The term run is used almost synonymously. A related meaning of both "to run" and "to execute" refers to
2360-580: The ABI). Other linked object files may also have entry points, which are used later by the linker when generating entry points of an executable file. Entry points are capable of passing on command arguments, variables, or other information as a local variable used by the Main() method. This way, specific options may be set upon execution of the program, and then interpreted by the program. Many programs use this as an alternative way to configure different settings, or perform
2419-436: The entry point is a static method named Main . Entry points apply both to source code and to executable files. However, in day-to-day software development , programmers specify the entry points only in source code, which makes them much better known. Entry points in executable files depend on the application binary interface (ABI) of the actual operating system, and are generated by the compiler or linker (if not fixed by
Entry point - Misplaced Pages Continue
2478-573: The first statement in the program. 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. In C and C++ , the function prototype of the main function must be equivalent to one of the following: Main function looks like entry point for application programmers (the application's entry point or main entry point). System programming reveals more information about
2537-488: The following: Command-line arguments are passed in args , similar to how it is done in C# or Java. 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. Like many other programming languages, Dart has an entry point that serves as
2596-400: The main function, by calling a specific exit function, or by the runtime catching exceptions or operating system signals. In many programming languages, the main function is where a program starts its execution. It enables high-level organization of the program's functionality, and typically has access to the command arguments given to the program when it was executed. The main function
2655-494: The names are to be taken literally, and the "void" in the parameter list is to be omitted, if strict conformance is desired. Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must always be int ; 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
2714-407: The next instruction starts being processed before the previous instruction has finished, which is possible because the cycle is broken up into separate steps. A system that executes a program is called an interpreter of the program. Loosely speaking, an interpreter directly executes a program. This contrasts with a language translator that converts a program from one language to another before it
2773-404: The number of address locations added to a base address in order to get to a specific absolute address . In this (original) meaning of offset, only the basic address unit, usually the 8-bit byte , is used to specify the offset's size. In this context an offset is sometimes called a relative address . In IBM System/360 instructions, a 12-bit offset embedded within certain instructions provided
2832-525: The operating system, otherwise the processor will simply continue executing beyond the end of the program, resulting in undefined behavior . Usually, there is not a single exit point specified in a program. However, in other cases runtimes ensure that programs always terminate in a structured way via a single exit point, which is guaranteed unless the runtime itself crashes; this allows cleanup code to be run, such as atexit handlers. This can be done by either requiring that programs terminate by returning from
2891-454: The program and then passes control to the program proper. In other cases, the program may initialize the runtime library itself. In simple systems, execution begins at the first statement, which is common in interpreted languages , simple executable formats, and boot loaders . In other cases, the entry point is at some other known memory address which can be an absolute address or relative address ( offset ). Alternatively, execution of
2950-421: The program only prints the result after reducing Start . Or even simpler One tells the compiler which option to use to generate the executable file. ANSI Common Lisp does not define a main function; instead, the code is read and evaluated from top to bottom in a source file. However, the following code will emulate a main function. In D , the function prototype of the main function looks like one of
3009-425: The program, and specifies the entry point elsewhere (in initialization procedure, or in reset interrupt vector for standalone programs). The parameters argc , argument count , and argv , argument vector , respectively give the number and values of the program's command-line arguments . The names of argc and argv may be any valid identifier in C, but it is common convention to use these names. In C++,
SECTION 50
#17328632477773068-409: The resources of a computer to be partitioned via the kernel . The terms are not universally interchangeable. Offset (computer science) In computer science , an offset within an array or other data structure object is an integer indicating the distance (displacement) between the beginning of the object and a given element or point, presumably within the same object. The concept of
3127-401: The side-effects-ful computation done by the program. The result of the computation represented by main is discarded; that is why main usually has type IO () , which indicates that the type of the result of the computation is () , the unit type , which contains no information. Execution (computing) Execution in computer and software engineering is the process by which
3186-521: The specific action of a user starting (or launching or invoking ) a program, as in "Please run the application." Prior to execution, a program must first be written. This is generally done in source code , which is then compiled at compile time (and statically linked at link time ) to produce an executable. This executable is then invoked, most often by an operating system, which loads the program into memory ( load time ), possibly performs dynamic linking , and then begins execution by moving control to
3245-413: The specific runtime system to generate correct code. Typically the runtime system will have some responsibility for setting up and managing the stack and heap , and may include features such as garbage collection , threads or other dynamic features built into the language. The instruction cycle (also known as the fetch–decode–execute cycle , or simply the fetch-execute cycle ) is the cycle that
3304-447: The standard library in Go. These can be accessed via os.Args and os.Exit respectively, both of which are included in the "os" package. A Haskell program must contain a name main bound to a value of type IO t , for some type t ; which is usually IO () . IO is a monad , which organizes side-effects in terms of purely functional code. The main value represents
3363-415: The starting point for a Dart program. The entry point is the first function that is executed when a program runs. In Dart, the entry point is typically a function named main . When a Dart program is run, the Dart runtime looks for a function named main and executes it. Any Dart code that is intended to be executed when the program starts should be included in the main function. Here is an example of
3422-400: The state they were in before they were suspended. This is achieved by a context switching. The running programs are often assigned a Process Context IDentifiers (PCID). In Linux-based operating systems, a set of data stored in registers is usually saved into a process descriptor in memory to implement switching of context. PCIDs are also used. Runtime , run time , or execution time
3481-451: The system can load and run as needed. An occasionally used technique is the fat binary , which consists of several executables for different targets packaged in a single file. Most commonly, this is implemented by a single overall entry point, which is compatible with all targets and branches to the target-specific entry point. Alternative techniques include storing separate executables in separate forks , each with its own entry point, which
#776223