Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C++, functions must be declared or defined before being use; that code cannot be C++.</p> <p>In C89 or pre-standard C, if the compiler encounters an identifier followed by an open parenthesis, it is a function call, and if there is no declaration or definition in effect, then the return type is implicitly <code>int</code> and the number and types of the arguments is unspecified. (Thus, in the example, <code>display()</code> is a function returning an <code>int</code> and taking an indefinite — but not variable — number of arguments.)</p> <p>In C99 or C11, in any strict compliance mode, you must have a declaration or definition of the function in scope before calling. It still doesn't have to be a prototype (the inferred declaration <code>int display();</code> is not a prototype, and the definition is also not a prototype — it would need to be <code>int display(void)</code> to provide a prototype!).</p> <p>Because of the inferred type for <code>display()</code> and the contradictory definition, you should get a compilation error, I believe. It would be at best a sloppy compiler that allowed it through, even in C89 mode. Indeed, I think even a pre-standard compiler should complain about the difference between the assumed and actual return types, but of course there was no standard so you couldn't complain (and, in any case, that standard is 24 years old now — compilers that only support that are verging on the archaic).</p> <p>Which compiler (and version) are you using on which platform?</p> <p>GCC 4.8.2 on Mac OS X 10.9, even with things set as permissive as possible, says:</p> <pre><code>dec.c:9:6: warning: conflicting types for ‘display’ [enabled by default] void display() ^ dec.c:5:5: note: previous implicit declaration of ‘display’ was here display(); ^ </code></pre>
 

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