<p>I have a library I created,</p>
<h3>File <em>mylib.c:</em></h3>
<pre><code>#include &lt;mylib.h&gt;

int
testlib() {
    printf(&quot;Hello, World!\n&quot;);
    return (0);
}
</code></pre>
<h3>File <em>mylib.h:</em></h3>
<pre><code>#include &lt;stdio.h&gt;
extern int testlib();
</code></pre>
<p>In my program, I've attempted to call this library function:</p>
<h3>File <em>myprogram.c</em>:</h3>
<pre><code>#include &lt;mylib.h&gt;

int
main (int argc, char *argv[]) {
    testlib();
    return (0);
}
</code></pre>
<p>When I attempt to compile this program I get the following error:</p>
<pre>In file included from myprogram.c:1
mylib.h:2 warning: function declaration isn't a prototype</pre>
<p>I'm using: <code>gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)</code></p>
<p>What is the proper way to declare a function prototype?</p>

[{'answer_id': 42133, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 5, 'selected': False, 'text': '<p>Try:</p>\n\n<pre><code>extern int testlib(void);\n</code></pre>\n'}, {'answer_id': 47693, 'author': 'Pramod', 'author_id': 1386292, 'author_profile': 'https://Stackoverflow.com/users/1386292', 'pm_score': 10, 'selected': True, 'text': "<p>In C <code>int foo()</code> and <code>int foo(void)</code> are different functions. <code>int foo()</code> accepts an arbitrary number of arguments, while <code>int foo(void)</code> accepts 0 arguments. In C++ they mean the same thing. I suggest that you use <code>void</code> consistently when you mean no arguments.</p>\n\n<p>If you have a variable <code>a</code>, <code>extern int a;</code> is a way to tell the compiler that <code>a</code> is a symbol that might be present in a different translation unit (C compiler speak for source file), don't resolve it until link time. On the other hand, symbols which are function names are anyway resolved at link time. The meaning of a storage class specifier on a function (<code>extern</code>, <code>static</code>) only affects its visibility and <code>extern</code> is the default, so <code>extern</code> is actually unnecessary.</p>\n\n<p>I suggest removing the <code>extern</code>, it is extraneous and is usually omitted. </p>\n"}, {'answer_id': 20843829, 'author': 'Keith Thompson', 'author_id': 827263, 'author_profile': 'https://Stackoverflow.com/users/827263', 'pm_score': 6, 'selected': False, 'text': "<p>Quick answer: change <code>int testlib()</code> to <code>int testlib(void)</code> to specify that the function takes no arguments.</p>\n<p>A <em>prototype</em> is by definition a function declaration that specifies the type(s) of the function's argument(s).</p>\n<p>A non-prototype function declaration like</p>\n<pre><code>int foo();\n</code></pre>\n<p>is an old-style declaration that does not specify the number or types of arguments. (Prior to the 1989 ANSI C standard, this was the only kind of function declaration available in the language.) You can call such a function with any arbitrary number of arguments, and the compiler isn't required to complain -- but if the call is inconsistent with the <em>definition</em>, your program has undefined behavior.</p>\n<p>For a function that takes one or more arguments, you can specify the type of each argument in the declaration:</p>\n<pre><code>int bar(int x, double y);\n</code></pre>\n<p>Functions with no arguments are a special case. Logically, empty parentheses would have been a good way to specify that a function takes no arguments, but that syntax was already in use for old-style function declarations, so the ANSI C committee invented a new syntax using the <code>void</code> keyword:</p>\n<pre><code>int foo(void); /* foo takes no arguments */\n</code></pre>\n<p>A function <em>definition</em> (which includes code for what the function actually does) also provides a <em>declaration</em>. In your case, you have something similar to:</p>\n<pre><code>int testlib()\n{\n    /* code that implements testlib */\n}\n</code></pre>\n<p>This provides a non-prototype declaration for <code>testlib</code>. As a definition, this tells the compiler that <code>testlib</code> has no parameters, but as a declaration, it only tells the compiler that <code>testlib</code> takes some unspecified but fixed number and type(s) of arguments.</p>\n<p>If you change <code>()</code> to <code>(void)</code> the declaration becomes a prototype.</p>\n<p>The advantage of a prototype is that if you accidentally call <code>testlib</code> with one or more arguments, the compiler will diagnose the error.</p>\n<p>(C++ has slightly different rules. C++ doesn't have old-style function declarations, and empty parentheses specifically mean that a function takes no arguments. C++ supports the <code>(void)</code> syntax for consistency with C. But unless you specifically need your code to compile both as C and as C++, you should probably use the <code>()</code> in C++ and the <code>(void)</code> syntax in C.)</p>\n"}]
['https://Stackoverflow.com/questions/42125', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3807/']