<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Declaration_%28computer_programming%29</id>
	<title>Declaration (computer programming) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Declaration_%28computer_programming%29"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Declaration_(computer_programming)&amp;action=history"/>
	<updated>2026-05-04T16:30:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Declaration_(computer_programming)&amp;diff=2596136&amp;oldid=prev</id>
		<title>imported&gt;Tea2min: Undid revision 1242492641 by 176.29.30.112 (talk)</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Declaration_(computer_programming)&amp;diff=2596136&amp;oldid=prev"/>
		<updated>2024-08-27T05:00:21Z</updated>

		<summary type="html">&lt;p&gt;Undid revision &lt;a href=&quot;/wiki143/index.php?title=Special:Diff/1242492641&quot; title=&quot;Special:Diff/1242492641&quot;&gt;1242492641&lt;/a&gt; by &lt;a href=&quot;/wiki143/index.php?title=Special:Contributions/176.29.30.112&quot; title=&quot;Special:Contributions/176.29.30.112&quot;&gt;176.29.30.112&lt;/a&gt; (&lt;a href=&quot;/wiki143/index.php?title=User_talk:176.29.30.112&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User talk:176.29.30.112 (page does not exist)&quot;&gt;talk&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Programming language construct specifying an identifier&amp;#039;s properties}}&lt;br /&gt;
{{cleanup|reason=Too many examples of unclear relevancy; not enough references; problematic mentions of header files and multiple declarations|date=December 2013}}&lt;br /&gt;
&lt;br /&gt;
In [[computer programming]], a &amp;#039;&amp;#039;&amp;#039;declaration&amp;#039;&amp;#039;&amp;#039; is a [[language construct]] specifying [[Identifier (computer programming)|identifier]] properties: it declares a word&amp;#039;s (identifier&amp;#039;s) meaning.&amp;lt;ref name=&amp;quot;c11&amp;quot;&amp;gt;&amp;quot;A declaration specifies the interpretation and attributes of a set of identifiers. A &amp;#039;&amp;#039;definition&amp;#039;&amp;#039; of an identifier is a declaration for that identifier that:&lt;br /&gt;
* for an object [variable or constant], causes storage to be reserved for that object;&lt;br /&gt;
* for a function, includes the function body;&lt;br /&gt;
* for an enumeration constant, is the (only) declaration of the identifier;&lt;br /&gt;
* for a typedef name, is the first (or only) declaration of the identifier.&amp;quot;&lt;br /&gt;
C11 specification, 6.7: Declarations, paragraph 5.&amp;lt;/ref&amp;gt; Declarations are most commonly used for [[subroutine|functions]], [[Variable (computer science)|variables]], [[Constant (computer programming)|constants]], and [[Class (computer programming)|classes]], but can also be used for other entities such as [[Enumerator (computer science)|enumerations]] and type definitions.&amp;lt;ref name=&amp;quot;c11&amp;quot;/&amp;gt; Beyond the name (the identifier itself) and the kind of entity (function, variable, etc.), declarations typically specify the [[data type]] (for variables and constants), or the [[type signature]] (for functions); types may also include dimensions, such as for [[Array data structure|array]]s. A declaration is used to announce the existence of the entity to the [[compiler]]; this is important in those [[strongly typed]] languages that require functions, variables, and constants, and their types to be specified with a declaration before use, and is used in [[forward declaration]].&amp;lt;ref&amp;gt;{{cite web&lt;br /&gt;
| access-date = 2011-06-08&lt;br /&gt;
| author = Mike Banahan&lt;br /&gt;
| publisher = GBdirect &lt;br /&gt;
| title = 2.5. Declaration of variables&lt;br /&gt;
| quote = [A] declaration [...] introduces just the name and type of something but allocates no storage[...].&lt;br /&gt;
| url = http://publications.gbdirect.co.uk/c_book/chapter2/variable_declaration.html}}&amp;lt;/ref&amp;gt; The term &amp;quot;declaration&amp;quot; is frequently contrasted with the term &amp;quot;definition&amp;quot;,&amp;lt;ref name=&amp;quot;c11&amp;quot;/&amp;gt; but meaning and usage varies significantly between languages; see below.&lt;br /&gt;
&lt;br /&gt;
Declarations are particularly prominent in languages in the [[ALGOL]] tradition, including the [[BCPL]] family, most prominently [[C (programming language)|C]] and [[C++]], and also [[Pascal (programming language)|Pascal]]. [[Java (programming language)|Java]] uses the term &amp;quot;declaration&amp;quot;, though Java does not require separate declarations and definitions.&lt;br /&gt;
&lt;br /&gt;
==Declaration vs. definition==&lt;br /&gt;
One basic dichotomy is whether or not a declaration contains a definition: for example, whether a variable or constant declaration [[initialization (programming)|specifies its value]], or only its type; and similarly whether a declaration of a function specifies the body ([[implementation]]) of the function, or only its type signature.&amp;lt;ref name=&amp;quot;c11&amp;quot;/&amp;gt; Not all languages make this distinction: in many languages, declarations always include a definition, and may be referred to as either &amp;quot;declarations&amp;quot; or &amp;quot;definitions&amp;quot;, depending on the language.{{efn|For example, Java uses &amp;quot;declaration&amp;quot; (class declaration, method declaration), while Python uses &amp;quot;definition&amp;quot; (class definition, function definition).&amp;lt;ref&amp;gt;[https://docs.python.org/2/reference/compound_stmts.html 7. Compound statements], &amp;#039;&amp;#039;The Python Language Reference&amp;#039;&amp;#039;&amp;lt;/ref&amp;gt;}} However, these concepts are distinguished in languages that require declaration before use (for which forward declarations are used), and in languages where interface and implementation are separated: the interface contains declarations, the implementation contains definitions.{{efn|This distinction is observed in Pascal &amp;quot;units&amp;quot; (modules), and in conventional C and C++ code organization, which has [[header file]]s consisting largely of pure declarations, and [[source file]]s consisting of definitions, though this is not always strictly observed, nor enforced by the language.}}&lt;br /&gt;
&lt;br /&gt;
In informal usage, a &amp;quot;declaration&amp;quot; refers only to a pure declaration (types only, no value or body), while a &amp;quot;definition&amp;quot; refers to a declaration that includes a value or body. However, in formal usage (in language specifications), &amp;quot;declaration&amp;quot; includes &amp;#039;&amp;#039;both&amp;#039;&amp;#039; of these senses, with finer distinctions by language: in C and C++, a declaration of a function that does not include a body is called a [[function prototype]], while a declaration of a function that does include a body is called a &amp;quot;function definition&amp;quot;. In Java declarations occur in two forms.  For public methods they can be presented in interfaces as method signatures, which consist of the method names, input types and output type. A similar notation can be used in the definition of [[abstract method]]s, which do not contain a definition. The enclosing class can be instantiated, rather a new derived class, which provides the definition of the method, would need to be created in order to create an [[Instance (computer science)|instance]] of the class.  Starting with [[Java 8]], the lambda expression was included in the language, which could be viewed as a function declaration.&lt;br /&gt;
&lt;br /&gt;
== Declarations and definitions ==&lt;br /&gt;
In the C-family of programming languages, declarations are often collected into [[header file]]s, which are included in other source files that reference and use these declarations, but don&amp;#039;t have access to the definition. The information in the header file provides the interface between code that uses the declaration and that which defines it, a form of [[information hiding]]. A declaration is often used in order to access functions or variables defined in different source files, or in a [[Library (computing)|library]]. A mismatch between the definition type and the declaration type generates a compiler error.&lt;br /&gt;
&lt;br /&gt;
For variables, definitions assign values to an area of memory that was reserved during the declaration phase. For functions, definitions supply the function body. While a variable or function may be declared many times, it is typically defined once (in [[C++]], this is known as the [[One Definition Rule]] or ODR).&lt;br /&gt;
&lt;br /&gt;
Dynamic languages such as [[JavaScript]] or [[Python (programming language)|Python]] generally allow functions to be redefined, that is, [[name binding|re-bound]]; a function is a variable much like any other, with a name and a value (the definition).&lt;br /&gt;
&lt;br /&gt;
Here are some examples of declarations that are not definitions, in C:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
extern char example1;&lt;br /&gt;
extern int example2;&lt;br /&gt;
void example3(void);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are some examples of declarations that are definitions, again in C:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
char example1; /* Outside of a function definition it will be initialized to zero.  */&lt;br /&gt;
int example2 = 5;&lt;br /&gt;
void example3(void) { /* definition between braces */ }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Undefined variables ==&lt;br /&gt;
{{main|Undefined variable}}&lt;br /&gt;
In some programming languages, an implicit declaration is provided the first time such a variable is encountered at [[compile time]].  In other languages, such a usage is considered to be an error, which may result in a diagnostic message. Some languages have started out with the implicit declaration behavior, but as they matured they provided an option to disable it (e.g. [[Perl]]&amp;#039;s &amp;quot;&amp;lt;code&amp;gt;use strict&amp;lt;/code&amp;gt;&amp;quot; or [[Visual Basic]]&amp;#039;s &amp;quot;&amp;lt;code&amp;gt;Option Explicit&amp;lt;/code&amp;gt;&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Scope (computer science)]]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
{{Notelist}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [http://www.cprogramming.com/declare_vs_define.html Declare vs Define in C and C++], Alex Allain&lt;br /&gt;
* [http://publications.gbdirect.co.uk/c_book/chapter8/declarations_and_definitions.html 8.2. Declarations, Definitions and Accessibility], &amp;#039;&amp;#039;The C Book,&amp;#039;&amp;#039; GBdirect&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/0e5kx78b.aspx Declarations and Definitions (C++)], MSDN&lt;br /&gt;
*:&amp;quot;Declarations tell the compiler that a program element or name exists. Definitions specify what code or data the name describes.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming language concepts]]&lt;br /&gt;
[[Category:Articles with example C code]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Tea2min</name></author>
	</entry>
</feed>