Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Entry point
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Programming languages== In many programming languages, the <code>main</code> 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-line argument|command arguments]] given to the program when it was executed. The main function is generally the first programmer-written [[subroutine|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 language]]s, execution begins at the first statement in the program. A non-exhaustive list of programming languages follows, describing their way of defining the main entry point: ===APL=== In [[APL (programming language)|APL]], when a workspace is loaded, the contents of "quad LX" (latent expression) variable is interpreted as an APL expression and executed. ===C and C++=== In [[C (programming language)|C]] and [[C++]], the [[function prototype]] of the main function must be equivalent to one of the following: <syntaxhighlight lang="c"> int main(); int main(void); int main(int argc, char **argv); </syntaxhighlight> The main function is the entry point for application programs written in ISO-standard C or C++. Low-level system programming (such as for a [[bare-metal]] [[embedded system]]) might specify a different entry point (for example via a reset [[interrupt vector]]) using functionality not defined by the language standard. The [[parameter (computer science)|parameters]] <code>argc</code>, ''argument count'', and <code>argv</code>, ''argument vector'',{{cn|date=January 2025}} respectively give the number and values of the program's [[command-line argument]]s. The names of <code>argc</code> and <code>argv</code> may be any valid identifier, but it is common convention to use these names. Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must always be <code>int</code>;<ref>Section 3.6.1.2, Standard C++ 2011 edition.</ref> for example, [[Unix]] (though not [[POSIX.1]]) and [[Windows]] have a third argument giving the program's [[environment variable|environment]], otherwise accessible through <code>getenv</code> in <code>[[stdlib.h]]</code>: <syntaxhighlight lang="c"> int main(int argc, char **argv, char **envp); </syntaxhighlight> [[Darwin (operating system)|Darwin]]-based operating systems, such as [[macOS]], have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:<ref>{{Cite web |url=http://unixjunkie.blogspot.com/2006/02/char-apple-argument-vector.html |title=The <code>char *apple</code> Argument Vector |access-date=2014-05-12 |archive-url=https://web.archive.org/web/20151222173356/http://unixjunkie.blogspot.com/2006/02/char-apple-argument-vector.html |archive-date=2015-12-22 |url-status=dead }}</ref> <syntaxhighlight lang="c"> int main(int argc, char **argv, char **envp, char **apple); </syntaxhighlight> 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: <code>EXIT_SUCCESS</code> (traditionally 0) and <code>EXIT_FAILURE</code>. The meaning of other possible return values is implementation-defined. In case a return value is not defined by the programmer, an implicit <code>return 0;</code> at the end of the <code>main()</code> function is inserted by the compiler; this behavior is required by the C++ standard. It is guaranteed that <code>argc</code> is non-negative and that <code>argv[argc]</code> is a [[null pointer]]. By convention, the command-line arguments specified by <code>argc</code> and <code>argv</code> include the name of the program as the first element if <code>argc</code> is greater than 0; if a user types a command of "<code>rm file</code>", the [[shell (computing)|shell]] will initialise the <code>[[rm (Unix)|rm]]</code> process with <code>argc = 2</code> and <code>argv = {"rm", "file", NULL}</code>. As <code>argv[0]</code> is the name that processes appear under in <code>[[ps (Unix)|ps]]</code>, <code>[[top (software)|top]]</code> etc., some programs, such as [[daemon (computing)|daemons]] or those running within an [[interpreter (computing)|interpreter]] or [[virtual machine]] (where <code>argv[0]</code> would be the name of the host executable), may choose to alter their argv to give a more descriptive <code>argv[0]</code>, usually by means of the <code>[[exec (system call)|exec]]</code> system call. The <code>main()</code> function is special; normally every C and C++ program must define it exactly once. If declared, <code>main()</code> must be declared as if it has external linkage; it cannot be declared <code>static</code> or <code>inline</code>. In C++, <code>main()</code> must be in the global [[namespace]] (i.e. <code>::main</code>), cannot be overloaded, and cannot be 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) <code>main()</code> cannot be called [[recursion (computer science)|recursively]] and cannot have its address taken. ===C#=== When executing a program written in [[C Sharp (programming language)|C#]], the [[Common Language Runtime|CLR]] searches for a static method marked with the <code>.entrypoint</code> IL directive, which takes either no arguments, or a single argument of type <code>string[]</code>, and has a return type of <code>void</code> or <code>int</code>, and executes it.<ref>{{cite web |url=http://msdn.microsoft.com/msdnmag/issues/04/02/NETConsoleApps/ |title=Console Applications in .NET, or Teaching a New Dog Old Tricks |publisher=Msdn.microsoft.com |date=2003-06-12 |access-date=2013-08-19 |archive-url=https://web.archive.org/web/20080204223443/http://msdn.microsoft.com/msdnmag/issues/04/02/NETConsoleApps/ |archive-date=2008-02-04 |url-status=dead }}</ref> <syntaxhighlight lang="csharp"> static void Main(); static void Main(string[] args); static int Main(); static int Main(string[] args); </syntaxhighlight> Command-line arguments are passed in <code>args</code>, similar to how it is done in Java. For versions of <code>Main()</code> 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 [[function signature|signatures]] of the entry point, which allow asynchronous execution in the <code>Main()</code> Method.<ref>{{cite web|url=https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.1/async-main.md|title=The official repo for the design of the C# programming language: Dotnet/Csharplang|website=[[GitHub]] |date=2019-08-26}}</ref> <syntaxhighlight lang="csharp"> static async Task Main() static async Task<int> Main() static async Task Main(string[]) static async Task<int> Main(string[]) </syntaxhighlight> The <code>Task</code> and <code>Task<int></code> types are the asynchronous equivalents of <code>void</code> and <code>int</code>. <code>async</code> is required to allow the use of asynchrony (the <code>await</code> keyword) inside the method. ===Clean=== [[Clean (programming language)|Clean]] is a functional programming language based on graph rewriting. The initial node is named <code>Start</code> and is of type <code>*World -> *World</code> if it ''changes'' the world or some fixed type if the program only prints the result after [[graph rewriting|reducing]] <code>Start</code>. <syntaxhighlight lang="clean"> Start :: *World -> *World Start world = startIO ... </syntaxhighlight> Or even simpler <syntaxhighlight lang="clean"> Start :: String Start = "Hello, world!" </syntaxhighlight> One tells the compiler which option to use to generate the executable file. ===Common Lisp=== 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 [[Emulator|emulate]] a main function. <syntaxhighlight lang="lisp"> (defun hello-main () (format t "Hello World!~%")) (hello-main) </syntaxhighlight> ===D=== In [[D (programming language)|D]], the [[function prototype]] of the main function looks like one of the following: <syntaxhighlight lang="D"> void main(); void main(string[] args); int main(); int main(string[] args); </syntaxhighlight> Command-line arguments are passed in <code>args</code>, similar to how it is done in C# or Java. For versions of <code>main()</code> returning an integer, similar to both C and C++, it is passed back to the environment as the exit status of the process. ===Dart=== [[Dart (programming language)|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 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 <code>main</code> . When a Dart program is run, the Dart runtime looks for a function named <code>main</code> and executes it. Any Dart code that is intended to be executed when the program starts should be included in the <code>main</code> function. Here is an example of a simple <code>main</code> function in Dart: <syntaxhighlight lang="Dart"> void main() { print("Hello, world!"); } </syntaxhighlight> In this example, the <code>main</code> function simply prints the text <code>Hello, world!</code> 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 <code>main</code> 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 the <code>@pragma("vm:entry-point")</code> annotation in Dart. However, in most cases, the <code>main</code> function is the entry point that should be used for Dart programs. ===FORTRAN=== [[FORTRAN]] does not have a main subroutine or function. Instead a <code>PROGRAM</code> statement as the first line can be used to specify that a program unit is a main program, as shown below. The <code>PROGRAM</code> statement cannot be used for recursive calls.<ref>XL FORTRAN for [[AIX]]. Language Reference. Third Edition, 1994. [[IBM]]</ref> <syntaxhighlight lang="fortran"> PROGRAM HELLO PRINT *, "Cint!" END PROGRAM HELLO </syntaxhighlight> Some versions of Fortran, such as those on 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. ===GNAT=== Using [[GNAT]], the programmer is not required to write a function named <code>main</code>; a source file containing a single subprogram can be compiled to an executable. The binder will however create a package <code>ada_main</code>, which will contain and export a C-style main function. ===Go=== In [[Go (programming language)|Go]] programming language, program execution starts with the <code>main</code> function of the <code>package main</code> <syntaxhighlight lang="go"> package main import "fmt" func main() { fmt.Println("Hello, World!") } </syntaxhighlight> There is no way to access arguments or a return code outside of the standard library in Go. These can be accessed via <code>os.Args</code> and <code>os.Exit</code> respectively, both of which are included in the <code>"os"</code> package. ===Haskell=== A [[Haskell (programming language)|Haskell]] program must contain a name <code>main</code> bound to a value of type <code>IO t</code>, for some type <code>t</code>;<ref>{{cite web |url=http://www.haskell.org/onlinereport/modules.html |title=The Haskell 98 Report: Modules |publisher=Haskell.org |access-date=2013-08-19 |archive-date=2013-08-19 |archive-url=https://web.archive.org/web/20130819042412/http://www.haskell.org/onlinereport/modules.html |url-status=live }}</ref> which is usually <code>IO ()</code>. <code>IO</code> is a [[monads in functional programming|monad]], which organizes [[Side effect (computer science)|side-effects]] in terms of [[purely functional programming|purely functional]] code.<ref>[http://geekrant.wordpress.com/2008/06/23/misconceptions/ Some Haskell Misconceptions: Idiomatic Code, Purity, Laziness, and IO] {{Webarchive|url=https://web.archive.org/web/20100727150353/http://geekrant.wordpress.com/2008/06/23/misconceptions/ |date=2010-07-27 }} β on Haskell's monadic IO></ref> The <code>main</code> value represents the side-effects-ful computation done by the program. The result of the computation represented by <code>main</code> is discarded; that is why <code>main</code> usually has type <code>IO ()</code>, which indicates that the type of the result of the computation is <code>()</code>, the [[unit type]], which contains no information. <syntaxhighlight lang="haskell"> main :: IO () main = putStrLn "Hello, World!" </syntaxhighlight> Command line arguments are not given to <code>main</code>; they must be fetched using another IO action, such as <code>[https://downloads.haskell.org/~ghc/latest/docs/html/libraries/base-4.11.1.0/System-Environment.html#v%3AgetArgs System.Environment.getArgs]</code>. ===Java=== [[Java (programming language)|Java]] programs start executing at the main [[method (computer science)|method]] of a class,<ref name="Oracle">{{cite web | title=The Java Language Environment | website=Oracle | url=https://www.oracle.com/technetwork/java/simple-142339.html | access-date=2020-03-14 | quote=Within the HelloWorld class, we declare a single method called main() which in turn contains a single method invocation to display the string "Hello world!" on the standard output. The statement that prints "Hello world!" does so by invoking the println method of the out object. The out object is a class variable in the System class that performs output operations on files. | archive-date=2019-04-20 | archive-url=https://web.archive.org/web/20190420152142/https://www.oracle.com/technetwork/java/simple-142339.html | url-status=live }}</ref><ref name="Schildt 2019 p. ">{{cite book | last=Schildt | first=Herbert | title=Java : a beginner's guide | publisher=McGraw-Hill Education | location=New York | year=2019 | isbn=978-1-260-44022-5 | oclc=1061561931 | page=46 | quote=A JAVA program begins with a call to main ().}}</ref><ref name="Learn Java">{{cite web | title=Hello, World! - Free Interactive Java Tutorial | website=Learn Java | url=https://www.learnjavaonline.org/ | access-date=2020-03-14 | quote=In Java, every line of code that can actually run needs to be inside a class. "public class Main {}" declares a class named Main, which is public, that means that any other class can access it.}}</ref><ref name="Learn Java II">{{cite web | title=Hello, World! - Free Interactive Java Tutorial | website=Learn Java | url=https://www.learnjavaonline.org/ | access-date=2020-03-14| quote="public static void main(String[] args) {} " is the entry point of our Java program. the main method has to have this exact signature in order to be able to run our program.}}</ref> which has one of the following [[method heading]]s: <syntaxhighlight lang="java"> public static void main(String[] args) public static void main(String... args) public static void main(String args[]) void main() </syntaxhighlight> Command-line arguments are passed in <code>args</code>. As in C and C++, the name "<code>main()</code>" is special. Java's main methods do not return a value directly, but one can be passed by using the <code>System.exit()</code> method. Unlike C, the name of the program is not included in <code>args</code>, because it is the name of the class that contains the main method, so it is already known. 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. The main function must be included within a class. This is because in Java everything has to be contained within a class. For instance, a [["Hello, World!" program|hello world]] program in Java may look like: <syntaxhighlight lang="java"> public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } </syntaxhighlight> To run this program, one must call <code>java HelloWorld</code> in the directory where the compiled [[Java class file|class file]] <code>HelloWorld.class</code>) exists. Alternatively, executable [[JAR (file format)|JAR]] files use a [[manifest file]] to specify the entry point in a manner that is filesystem-independent from the user's perspective. ===LOGO=== In [[Logo (programming language)|FMSLogo]], the procedures when loaded do not execute. To make them execute, it is necessary to use this code: to procname ... ; Startup commands (such as print [Welcome]) end make "startup [procname] The variable <code>startup</code> is used for the startup list of actions, but the convention is that this calls a procedure that runs the actions. That procedure may be of any name. ===OCaml=== [[OCaml]] has no <code>main</code> function. Programs are evaluated from top to bottom. Command-line arguments are available in an array named <code>Sys.argv</code> and the exit status is 0 by default. Example: <syntaxhighlight lang="ocaml"> print_endline "Hello World" </syntaxhighlight> ===Pascal=== In [[Pascal (programming language)|Pascal]], the main procedure is the only unnamed [[block (programming)|block]] in the program. Because Pascal programs define procedures and functions in a more rigorous bottom-up order than C, C++ or Java programs, the main procedure is usually the last block in the program. Pascal does not have a special meaning for the name "<code>main</code>" or any similar name. <syntaxhighlight lang="pascal"> program Hello(Output); begin writeln('Hello, world!'); end. </syntaxhighlight> Command-line arguments are counted in <code>ParamCount</code> and accessible as strings by <code>ParamStr(n)</code>, with n between 0 and <code>ParamCount</code>. Versions of Pascal that support units or modules may also contain an unnamed block in each, which is used to initialize the module. These blocks are executed before the main program entry point is called. ===Perl=== In [[Perl]], there is no main function. Statements are executed from top to bottom, although statements in a <code>BEGIN</code> block are executed before normal statements. Command-line arguments are available in the special array <code>@ARGV</code>. Unlike C, <code>@ARGV</code> does not contain the name of the program, which is <code>$0</code>. ===PHP=== PHP does not have a "main" function. 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. ===Pike=== In [[Pike (programming language)|Pike]] syntax is similar to that of C and C++. The execution begins at <code>main</code>. The "<code>argc</code>" variable keeps the number of [[Parameter (computer science)|arguments]] passed to the program. The "<code>argv</code>" variable holds the value associated with the arguments passed to the program. Example: <syntaxhighlight lang="pike"> int main(int argc, array(string) argv) </syntaxhighlight> ===Python=== [[Python (programming language)|Python]] programs are evaluated top-to-bottom, as is usual in scripting languages: the entry point is the start of the source code. Since definitions must precede use, programs are typically structured with definitions at the top and the code to execute at the bottom (unindented), similar to code for a [[one-pass compiler]], such as in Pascal. Alternatively, a program can be structured with an explicit <code>main</code> function containing the code to be executed when a program is executed directly, but which can also be invoked by importing the program as a module and calling the function. This can be done by the following idiom, which relies on the internal variable <code>__name__</code> being set to <code>__main__</code> 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:<ref>{{cite web |url=https://www.artima.com/weblogs/viewpost.jsp?thread=4829 |title=Python main() functions |author=Guido van Rossum |author-link=Guido van Rossum |date=May 15, 2003 |postscript=, |access-date=June 29, 2015 |archive-date=July 11, 2015 |archive-url=https://web.archive.org/web/20150711062438/http://www.artima.com/weblogs/viewpost.jsp?thread=4829 |url-status=live }}[https://www.artima.com/forums/flat.jsp?forum=106&thread=4829 comments]</ref><ref>[http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#modules-scripts Code Like a Pythonista: Idiomatic Python] {{Webarchive|url=https://web.archive.org/web/20140527204143/http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#modules-scripts |date=2014-05-27 }}βon Python scripts used as modules</ref><ref>{{cite web |url=http://nedbatchelder.com/blog/200306/python_main_functions.html |title=Python main() functions |author=Ned Batchelder |date=6 June 2003 |access-date=29 June 2015 |archive-date=20 September 2015 |archive-url=https://web.archive.org/web/20150920223603/http://nedbatchelder.com/blog/200306/python_main_functions.html |url-status=live }}</ref> <syntaxhighlight lang="python"> import sys def main(argv): n = int(argv[1]) print(n + 1) if __name__ == "__main__": sys.exit(main(sys.argv)) </syntaxhighlight> In this idiom, the call to the named entry point <code>main</code> 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. This contrasts with C, where these are done ''implicitly'' by the runtime, based on convention. ===QB64=== The [[QB64]] language has no main function, the code that is not within a function, or subroutine is executed first, from top to bottom: <syntaxhighlight lang="bmax"> print "Hello World! a ="; a = getInteger(1.8d): print a </syntaxhighlight> <syntaxhighlight lang="vbnet"> function getInteger(n as double) getInteger = int(n) end function </syntaxhighlight> Command line arguments (if any) can be read using the {{mono|COMMAND$}} function: <syntaxhighlight lang="vbnet"> dim shared commandline as string commandline = COMMAND$ </syntaxhighlight> <syntaxhighlight lang="basic"> 'Several space-separated command line arguments can be read using COMMAND$(n) commandline1 = COMMAND$(2) </syntaxhighlight> ===Ruby=== In [[Ruby (programming language)|Ruby]], there is no distinct main function. Instead, code written outside of any <code>class .. end</code> or <code>module .. end</code> scope is executed in the context of a special "<code>main</code>" object. This object can be accessed using <code>self</code>: <syntaxhighlight lang="irb"> irb(main):001:0> self => main </syntaxhighlight> It has the following properties: <syntaxhighlight lang="irb"> irb(main):002:0> self.class => Object irb(main):003:0> self.class.ancestors => [Object, Kernel, BasicObject] </syntaxhighlight> Methods defined outside of a <code>class</code> or <code>module</code> scope are defined as private methods of the "<code>main</code>" object. Since the class of "<code>main</code>" is <code>Object</code>, such methods become private methods of almost every object: <syntaxhighlight lang="irb"> irb(main):004:0> def foo irb(main):005:1> 42 irb(main):006:1> end => nil irb(main):007:0> foo => 42 irb(main):008:0> [].foo NoMethodError: private method `foo' called for []:Array from (irb):8 from /usr/bin/irb:12:in `<main>' irb(main):009:0> false.foo NoMethodError: private method `foo' called for false:FalseClass from (irb):9 from /usr/bin/irb:12:in `<main>' </syntaxhighlight> The number and values of command-line arguments can be determined using the <code>ARGV</code> constant array: <syntaxhighlight lang="console"> $ irb /dev/tty foo bar tty(main):001:0> ARGV ARGV => ["foo", "bar"] tty(main):002:0> ARGV.size ARGV.size => 2 </syntaxhighlight> The first element of <code>ARGV</code>, <code>ARGV[0]</code>, contains the first command-line argument, not the name of program executed, as in C. The name of program is available using <code>$0</code> or <code>$PROGRAM_NAME</code>.<ref>[https://docs.ruby-lang.org/en/master/ARGF.html class ARGF] β on Ruby <code>ARGV</code></ref> Similar to Python, one could use: <syntaxhighlight lang="ruby"> if __FILE__ == $PROGRAM_NAME # Put "main" code here end </syntaxhighlight> to execute some code only if its file was specified in the <code>ruby</code> invocation. ===Rust=== In Rust, the entry point of a program is a function named <code>main</code>. Typically, this function is situated in a file called <code>main.rs</code> or <code>lib.rs</code>. <syntaxhighlight lang="rust"> // In `main.rs` fn main() { println!("Hello, World!"); } </syntaxhighlight> Additionally, as of Rust 1.26.0, the main function may return a <code>Result</code>:<ref>{{cite web |title=Releases.md |url=https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1260-2018-05-10 |publisher=GitHub Rust |access-date=15 February 2019 |archive-date=2015-05-15 |archive-url=https://web.archive.org/web/20150515221302/https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1260-2018-05-10 |url-status=live }}</ref> <syntaxhighlight lang="rust"> fn main() -> Result<(), std::io::Error> { println!("Hello, World!"); Ok(()) // Return a type `Result` of value `Ok` with the content `()`, i.e. an empty tuple. } </syntaxhighlight> ===Swift=== When run in an [[Xcode]] Playground,<ref>Not to be confused with [https://www.apple.com/swift/playgrounds/ Swift Playgrounds] {{Webarchive|url=https://web.archive.org/web/20220708182700/https://www.apple.com/swift/playgrounds/ |date=2022-07-08 }}, an Apple-developed iPad app for learning the Swift programming language.</ref> [[Swift (programming language)|Swift]] behaves like a scripting language, executing statements from top to bottom; top-level code is allowed. <syntaxhighlight lang="swift"> // HelloWorld.playground let hello = "hello" let world = "world" let helloWorld = hello + " " + world print(helloWorld) // hello world </syntaxhighlight> [[Cocoa (API)|Cocoa]]- and [[Cocoa Touch]]-based applications written in Swift are usually initialized with the <code>@NSApplicationMain</code> and <code>@UIApplicationMain</code> attributes, respectively. Those attributes are equivalent in their purpose to the <code>main.m</code> file in [[Objective-C]] projects: they implicitly declare the <code>main</code> function that calls <code>UIApplicationMain(_:_:_:_:)</code><ref>{{Cite web|url=https://developer.apple.com/documentation/uikit/1622933-uiapplicationmain|title=UIApplicationMain(_:_:_:_:) β UIKit|website=Apple Developer Documentation|access-date=2019-01-12|archive-date=2019-01-12|archive-url=https://web.archive.org/web/20190112195043/https://developer.apple.com/documentation/uikit/1622933-uiapplicationmain|url-status=live}}</ref> which creates an instance of <code>UIApplication</code>.<ref>{{Cite web|url=https://developer.apple.com/documentation/uikit/uiapplication|title=UIApplication β UIKit|website=Apple Developer Documentation|access-date=2019-01-12|archive-date=2019-01-13|archive-url=https://web.archive.org/web/20190113062642/https://developer.apple.com/documentation/uikit/uiapplication|url-status=live}}</ref> The following code is the default way to initialize a Cocoa Touch-based [[iOS]] app and declare its application delegate.<syntaxhighlight lang="swift"> // AppDelegate.swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { return true } } </syntaxhighlight> ===Visual Basic=== In [[Visual Basic]], when a project contains no forms, the startup object may be the <code>Main()</code> procedure. The <code>Command$</code> function can be optionally used to access the argument portion of the command line used to launch the program: <syntaxhighlight lang="vbscript"> Sub Main() Debug.Print "Hello World!" MsgBox "Arguments if any are: " & Command$ End Sub </syntaxhighlight> ===Xojo=== In [[Xojo]], there are two different project types, each with a different main entry point. Desktop (GUI) applications start with the <code>App.Open</code> event of the project's <code>Application</code> object. Console applications start with the <code>App.Run</code> event of the project's <code>ConsoleApplication</code> object. In both instances, the main function is automatically generated, and cannot be removed from the project.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)