<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Function_prototype</id>
	<title>Function prototype - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Function_prototype"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Function_prototype&amp;action=history"/>
	<updated>2026-04-06T14:03:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Function_prototype&amp;diff=750198&amp;oldid=prev</id>
		<title>24.50.56.74: /* Example */</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Function_prototype&amp;diff=750198&amp;oldid=prev"/>
		<updated>2025-09-12T15:38:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Example&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Declaration of a function&amp;#039;s name and type signature but not body}}&lt;br /&gt;
{{About|function declarations|the prototype property of JavaScript functions and objects|JavaScript#Object-orientation (prototype-based)|other uses|Software prototyping}}&lt;br /&gt;
{{more citations needed|date=September 2016}}&lt;br /&gt;
&lt;br /&gt;
In [[computer programming]], a &amp;#039;&amp;#039;&amp;#039;function prototype&amp;#039;&amp;#039;&amp;#039;  is a [[Declaration (computer programming)|declaration]] of a [[function (programming)|function]] that specifies the function&amp;#039;s name and [[type signature]] ([[arity]], [[data type]]s of [[parameter (computer programming)|parameters]], and [[return type]]), but omits the function body. While a function definition specifies &amp;#039;&amp;#039;how&amp;#039;&amp;#039; the function does what it does (the &amp;quot;implementation&amp;quot;), a function prototype merely specifies its interface, i.e. &amp;#039;&amp;#039;what&amp;#039;&amp;#039; data types go in and come out of it. The term &amp;quot;function prototype&amp;quot; is particularly used in the context of the programming languages [[C (programming language)|C]] and [[C++]] where placing [[forward declaration]]s of functions in [[header file]]s allows for splitting a program into [[translation unit (programming)|translation unit]]s, i.e. into parts that a [[compiler]] can separately translate into [[object file]]s, to be combined by a [[linker (computing)|linker]] into an [[executable]] or a [[library (computing)|library]]. The function declaration precedes the function definition, giving details of name, return type, and storage class along with other relevant attributes.&amp;lt;ref&amp;gt;{{Cite web |last=TylerMSFT |date=2023-01-25 |title=Function Prototypes |url=https://learn.microsoft.com/en-us/cpp/c-language/function-prototypes?view=msvc-170 |access-date=2023-08-09 |website=learn.microsoft.com |language=en-us}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function prototypes can be used when either:&amp;lt;ref&amp;gt;{{Cite web |date=2018-10-25 |title=Function prototypes |url=https://www.ibm.com/docs/es/rbd/9.1.1.2?topic=functions-function-prototypes |access-date=2023-08-09 |website=www.ibm.com |language=en-us}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Defining an ExternalType&lt;br /&gt;
* Creating an Interface part&lt;br /&gt;
&lt;br /&gt;
In a prototype, parameter names are optional (and in C/C++ have function prototype [[Scope (computer science)|scope]], meaning their scope ends at the end of the prototype), however, the type is necessary along with all modifiers (e.g. if it is a [[Pointer (computer programming)|pointer]] or a reference to {{mono|[[const]]}} parameter) except {{mono|const}} alone.&lt;br /&gt;
&lt;br /&gt;
In [[object-oriented programming]], [[Protocol (object-oriented programming)|interfaces]] and [[Method (computer programming)#Abstract methods|abstract methods]] serve much the same purpose.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Consider the following function prototype:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void sum(int a, int b);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or, without named parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void sum(int, int);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or, with trailing return types ([[C++]] only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
auto sum(int, int) -&amp;gt; void;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function prototypes include the function signature, the name of the function, return type and access specifier. In this case the name of the function is &amp;quot;sum&amp;quot;. The function signature defines the number of parameters and their types. The return type is &amp;quot;void&amp;quot;. This means that the function is not going to return any value. Note that the parameter names in the first example are optional.&lt;br /&gt;
&lt;br /&gt;
== Uses ==&lt;br /&gt;
In early versions of C, if a function was not previously declared and its name occurred in an expression followed by a left parenthesis, it was implicitly declared as a function that returns an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; and nothing was assumed about its arguments. In this case the compiler would not be able to perform compile-time validity checking of the number and type(s) of arguments. &lt;br /&gt;
The [[C99]] standard requires the use of prototypes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;limits.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Function prototype &lt;br /&gt;
char myFunction(int a);&lt;br /&gt;
&lt;br /&gt;
int main(void) {&lt;br /&gt;
    putchar(myFunction(-1)); // Correctly formatted call&lt;br /&gt;
    putchar(myFunction(1.5)); // Compiler warning: type mismatch&lt;br /&gt;
    putchar(myFunction(&amp;quot;IncorrectArgType&amp;quot;)); // Compiler warning: type mismatch&lt;br /&gt;
    putchar(myFunction()); // Compiler error: too few arguments&lt;br /&gt;
&lt;br /&gt;
    // Although adding 1 to INT_MAX is an integer overflow error,&lt;br /&gt;
    // it cannot be detected at compile time&lt;br /&gt;
    putchar(myFunction(INT_MAX + 1));&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Function definition&lt;br /&gt;
char myFunction(int n) {&lt;br /&gt;
    if (n &amp;gt; 0) {&lt;br /&gt;
        return &amp;#039;&amp;gt;&amp;#039;;&lt;br /&gt;
    } else if (n &amp;lt; 0) {&lt;br /&gt;
        return &amp;#039;&amp;lt;&amp;#039;; &lt;br /&gt;
    } else {&lt;br /&gt;
        return &amp;#039;=&amp;#039;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function {{mono|MyFunction}} expects to be called with an integer argument.  By including the function prototype, you inform the compiler that the function takes one integer argument and you enable the compiler to catch incorrectly specified calls.&lt;br /&gt;
&lt;br /&gt;
=== Creating library interfaces ===&lt;br /&gt;
By placing function prototypes in a [[Include directive|header file]], one can specify an [[protocol (object-oriented programming)|interface]] for a [[Library (computing)|library]].&lt;br /&gt;
&lt;br /&gt;
=== Class declaration ===&lt;br /&gt;
In C++, function prototypes are also used in [[class (computer science)|class]] definitions.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Modular programming]]&lt;br /&gt;
* [[Protocol (object-oriented programming)]]&lt;br /&gt;
* [[Method (computer programming)#Abstract methods|Abstract method]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
{{refbegin|}}&lt;br /&gt;
* {{cite book|title=The C Programming Language|last1=Kernighan|first1=Brian W.|author-link1=Brian Kernighan|last2=Ritchie Afree|first2=Dennis M.|author-link2=Dennis Ritchie|year=1988|publisher=Prentice Hall PTR|place=Upper Saddle River, NJ|edition=2nd|isbn=0-13-110362-8|url-access=registration|url=https://archive.org/details/cprogramminglang00bria}}&lt;br /&gt;
{{refend}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Subroutines]]&lt;br /&gt;
[[Category:C programming language family]]&lt;br /&gt;
[[Category:Computer programming]]&lt;/div&gt;</summary>
		<author><name>24.50.56.74</name></author>
	</entry>
</feed>