Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is NO overloading of <code>main</code> even in C++. Main function is the entry point for a program and only a single definition should exist.</p> <p>For Standard C</p> <blockquote> <p>For a hosted environment (that's the normal one), the C99 standard says:</p> <blockquote> <h3>5.1.2.2.1 Program startup</h3> <p>The function called at program startup is named <code>main</code>. The implementation declares no prototype for this function. It shall be defined with a return type of <code>int</code> and with no parameters:</p> <pre><code>int main(void) { /* ... */ } </code></pre> <p>or with two parameters (referred to here as <code>argc</code> and <code>argv</code>, though any names may be used, as they are local to the function in which they are declared):</p> <pre><code>int main(int argc, char *argv[]) { /* ... */ } </code></pre> <p>or equivalent;<sup>9)</sup> or in some other implementation-defined manner.</p> <p><sup>9)</sup> Thus, <code>int</code> can be replaced by a typedef name defined as <code>int</code>, or the type of <code>argv</code> can be written as <code>char **argv</code>, and so on.</p> </blockquote> </blockquote> <p>For standard C++:</p> <blockquote> <h3>3.6.1 Main function [basic.start.main]</h3> <p>1 A program shall contain a global function called main, which is the designated start of the program. [...]</p> <p>2 An implementation <strong><em>shall not</em></strong> predefine the main function. <strong>This function shall not be overloaded</strong>. It shall have a return type of type int, but otherwise its type is implementation defined. All implementations shall allow both of the following definitions of main:</p> <pre><code>int main() { /* ... */ } </code></pre> <p>and</p> <pre><code>int main(int argc, char* argv[]) { /* ... */ } </code></pre> </blockquote> <p>The C++ standard explicitly says "It [the main function] shall have a return type of type int, but otherwise its type is implementation defined", and requires the same two signatures as the C standard. </p> <p>In a <strong>hosted environment</strong> (A C environment which also supports the C libraries) - the Operating System calls <code>main</code>. </p> <p>In a <strong>non-hosted environment</strong> (One intended for embedded applications) you can always change the entry point (or exit) of your program using the pre-processor directives like</p> <pre><code>#pragma startup [priority] #pragma exit [priority] </code></pre> <p>Where priority is an optional integral number.</p> <p>Pragma startup executes the function before the main (priority-wise) and pragma exit executes the function after the main function. If there is more than one startup directive then priority decides which will execute first. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload