Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between function declaration and signature?

In C or C++ what is the difference between function declaration and function signature?

I know something of function declaration but function signature is totally new to me. What is the point of having the concept of function signature? What are the two concepts used for actually?

Thanks!

like image 220
Tim Avatar asked Feb 24 '10 00:02

Tim


People also ask

What is the difference between function signature and function prototype?

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 "Sum". The function signature defines the number of parameters and their types. The return type is "void".

What is the function of a signature?

A function signature (or type signature, or method signature) defines input and output of functions or methods. A signature can include: parameters and their types. a return value and type.

What is the difference between function prototype and signature in Java?

A method signature is a combination of method name and parameter list . It has the capability to write methods that have the same name but obtain different parameters. Function prototypes are a C concept that is not relevant to Java. A function prototype is basically a definition for a function.

What is a function declaration?

A function declaration introduces an identifier that designates a function and, optionally, specifies the types of the function parameters (the prototype). Function declarations (unlike definitions) may appear at block scope as well as file scope.


1 Answers

A function declaration is the prototype for a function (or it can come from the function definition if no prototype has been seen by the compiler at that point) - it includes the return type, the name of the function and the types of the parameters (optionally in C).

A function signature is the parts of the function declaration that the compiler uses to perform overload resolution. Since multiple functions might have the same name (ie., they're overloaded), the compiler needs a way to determine which of several possible functions with a particular name a function call should resolve to. The signature is what the compiler considers in that overload resolution. Specifically, the standard defines 'signature' as:

the information about a function that participates in overload resolution: the types of its parameters and, if the function is a class member, the cv-qualifiers (if any) on the function itself and the class in which the member function is declared.

Note that the return type is not part of the function signature. As the standard says in a footnote, "Function signatures do not include return type, because that does not participate in overload resolution".

like image 82
Michael Burr Avatar answered Sep 28 '22 05:09

Michael Burr