Tom said:
Tony, you can think of a declaration as reserving space for a variable,
without giving it a value. A definition assigns a value to a variable,
optionally declaring it at the same time according to the syntax of the
language. E.g.:
int i; declares the variable i, without assigning a specific value
i = 3; defines the value of a pre-declared variable
Except that the C# specification refers to that as "assigns", not
"defines", or "assignment" rather than "definition".
[...]
This is accepted terminology, although since most people don't study
computer language theory or write compilers the distinction is rarely
observed these days, even among experienced programmers.
Accepted by whom? According to what reference? And if "definition" is
the assignment of a value to a variable, what is the "definition" of a
class?
In C, I can declare a function:
void function(void);
Or I can define the function:
void function(void)
{
printf("foo");
}
Absent any other declaration, one might consider the definition of a
function to also be its declaration.
In fact, not that this is an authoritative source or anything, but the
first several programming-related hits on Google for "declaration
definition" directly contradict your statement:
http://ee.hawaii.edu/~tep/EE160/Book/chap14/subsection2.1.1.4.html
http://wiki.answers.com/Q/What_is_the_difference_between_declaration_and_a_definition_in_C
http://wiki.answers.com/Q/Difference_between_the_definition_and_declaration_of_a_variable_in_c
All of the above stipulate that a "definition" of something allocates
space for it. None suggest that actually assigning a value to a
variable has anything to do with declaration or definition.
Given my usage of "definition" for types, methods, etc. I'm much more
comfortable agreeing that one can apply the word to a declaration of a
variable where storage for the variable is allocated as part of the
declaration, than I am in saying that a variable is undefined until it's
been assigned. The variable itself is defined as soon as it's declared;
its _value_ may be undefined until assignment, but that's something else
entirely.
But all that said, just goes to show: my previous point that there may
not be great consensus on the use of the terms is reasonably valid.
Note that the C# 3.0 specification uses the word "definition" in
relation to a variable only once, and the usage in that case is
ambiguous. For variables generally, the spec uses the term "declared"
to refer to where the actual variable exists in the code, and then uses
more specific terminology to address questions such as assignment,
scope, and lifetime.
Pete