4

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...

3

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);
  • Another term for "prototype" in this context is a method signature. – Mike Rosenblum May 2 '11 at 2:05
1

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

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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