Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat if I omit the return type of main function in C?
    primarykey
    data
    text
    <p>Before anyone may mark it duplicate of related questions. I emphasize I <em>DO</em> have read all those questions. But I still have some interrogations(yep, some little pedantic :) )</p> <p><strong>For C</strong></p> <p>Some conclusions:</p> <pre><code>1. In C89(C90), this is _undefined_ . 2. In C99(or C11), a type of int is madatory; control flow reached the closing } will return a value of 0. </code></pre> <p>Here comes my interrogations.</p> <ol> <li><p>In <a href="http://www.vmunix.com/~gabor/c/draft.html" rel="nofollow">c89</a>, I have found nothing about <strong>undefined</strong>, but <strong>unspecified</strong>?</p> <p><strong>Detail:</strong> The related parts in <strong><a href="http://www.vmunix.com/~gabor/c/draft.html" rel="nofollow">C89</a></strong> are <strong>5.1.2.2.1 Program startup</strong> and <strong>5.1.2.2.3 Program termination</strong> (<strong>NOTE</strong> : both are under the <strong>5.1.2.2 Hosted environment</strong> section, within which our later discussion is limitted)</p> <p><strong>Cite:</strong> -- 5.1.2.2.3 Program termination --</p> <p><code>A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument.10 If the } that terminates the main function is reached, the termination status returned to the host environment is unspecified.</code></p> <p>Just note that part: <strong>If the } that terminates ...</strong> , it clearly says that if we omit the return type - thus the } will be reached at -<br> the termination status is <strong>unspecified</strong> </p> <p>According the definition of the standard of <strong>undefined</strong> and <strong>unspecified</strong>, Should I say that it gives <strong>unspecified value</strong> since whatever it return is a legal int value, but the <strong>consequese is undefined</strong>-we could not predict what value will lead to what catastrophic consequese?</p></li> <li><p>In c99, a type of int is madatory, but <code>gcc --std=c99</code> given a test without int type(no return type actually) gives only <strong>waring:return type of ‘main’ is not ‘int’</strong> ,but not <strong>error</strong> ?</p> <p><strong>Detail:</strong> the related parts are the same as that in c89.</p> <p><strong>Cite:</strong> -- 5.1.2.2.1 Program startup --</p> <p><code>It shall be defined with a return type of int and ...</code> </p> <p>and -- 4. Conformance --</p> <p><code>1. In this International Standard, ‘‘shall’’ is to be interpreted as a requirement on an implementation or on a program; conversely, ‘‘shall not’’ is to be interpreted as a prohibition.</code></p> <p>So <strong>shall</strong> should be interpreted as <strong>madatory</strong> in this standard, why gcc with swith <strong>--std=c99</strong> violated this? </p></li> </ol>
    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.
 

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