Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I see the terms "declaration," "prototype" and "symbol" thrown around interchangeably a lot when it comes to code like the following:

void MyUndefinedFunction();

The same goes for "definition" and "implementation" for things like this:

void MyClass::MyMethod()
{
    // Actual code here.
}

Are there any distinctions between the terms, or are they truly synonymous?

EDIT: I'm unsure whether or not this belongs on Stack Overflow...

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

In C, they are different.

A "symbol" is the name of a variable, constant, or function, e.g. i, sqrt, or value.

A "declaration" indicates that the given variable, constant, or function exists, and tells its type, e.g.

const int i;
double sqrt();
float value;

A "prototype" provides information about the arguments to a function as well as its return type, e.g.

double sqrt(double value);
share|improve this answer
    
Another term for "prototype" in this context is a method signature. –  Mike Rosenblum May 2 '11 at 2:05
add comment

Declarations are simply the act of declaring a variable into existence. The definition is what a variable is holding, or the code that a function will execute.

void MyUndefinedFunction(); is a prototype because it's not being defined to do anything (it is being declared). Implementing a variable or function would be the act of using it, or implementing it into your code, to accomplish a task.

void MyFunction(); // The function prototype

void MyFunctoin() {

// The code to be executed by MyFunction() (the definition)

}

if (something happens) {

MyFunction() // The implementation of the function into your program

}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.