Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The current standard as at the time of this answer (C11) explicitly mentions these two:</p> <pre><code>int main(void); int main(int argc, char* argv[]); </code></pre> <p>although it does mention the phrase "or equivalent" with the following footnote:</p> <blockquote> <p>Thus, <code>int</code> can be replaced by a <code>typedef</code> 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> <p>In addition, it also provides for more (implementation-defined) possibilities.</p> <p>The relevant section (section 5.1.2.2.1 in C11, but this particular aspect is unchanged from C99) states:</p> <blockquote> <p>The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:</p> <pre><code>int main(void) { /* ... */ } </code></pre> <p>or with two parameters (referred to here as argc and argv, 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; or in some other implementation-defined manner.</p> <p>If they are declared, the parameters to the main function shall obey the following constraints:</p> <ul> <li><p>The value of <code>argc</code> shall be nonnegative.</p></li> <li><p><code>argv[argc]</code> shall be a null pointer.</p></li> <li><p>If the value of argc is greater than zero, the array members <code>argv[0]</code> through <code>argv[argc-1]</code> inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup. The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. If the host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are received in lowercase.</p></li> <li><p>If the value of <code>argc</code> is greater than zero, the string pointed to by <code>argv[0]</code> represents the program name; <code>argv[0][0]</code> shall be the null character if the program name is not available from the host environment. If the value of <code>argc</code> is greater than one, the strings pointed to by <code>argv[1]</code> through <code>argv[argc-1]</code> represent the program parameters.</p></li> <li><p>The parameters <code>argc</code> and <code>argv</code> and the strings pointed to by the <code>argv</code> array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.</p></li> </ul> </blockquote> <p>Note that this is for a hosted environment, the ones you normally see in C programs. A free-standing environment (such as an embedded system) is far less constrained, as stated in 5.1.2.1 of that same standard:</p> <blockquote> <p>In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. Any library facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined.</p> </blockquote>
 

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