what is the difference between function declaration and signature? what is the difference between function declaration and signature? c c

what is the difference between function declaration and signature?


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


The standard defines two terms: declaration and definition. A definition is a tentative declaration. However, the C99 and C++03 standards have slightly varying definitions.

From C++0x draft:

Appendix C

8.3.5 Change: In C++, a function declaredwith an empty parameter list takes noarguments. In C, an empty parameterlist means that the number and type ofthe function arguments are unknown"

Definitions

1.3.11 signature

the name and the parameter-type-list(8.3.5) of a function, as well as theclass, concept, concept map, ornamespace of which it is a member. Ifa function or function template is aclass member its signatureadditionally includes thecv-qualifiers (if any) and theref-qualifier (if any) on the functionor function template itself. Thesignature of a constrained member(9.2) includes its templaterequirements. The signature of afunction template additionallyincludes its return type, its templateparameter list, and its templaterequirements (if any). The signatureof a function template specializationincludes the signature of the templateof which it is a specialization andits template arguments (whetherexplicitly specified or deduced). [Note: Signatures are used as a basisfor name mangling and linking.—endnote ]


The function signature doesn't include the return type or linkage type of the function.

OK, Wikipedia disagrees with me on the return type being included. However I know that the return type is not used by the compiler when deciding if a function call matches the signature. This previous StackOverflow question appears to agree: Is the return type part of the function signature?