Function signature and Function Prototype

Function Prototype:
ReturnType FunctionName(Parameter list);

Function Signature:
FunctionName(Parameter list);

Please correct me if I am wrong.
1
2
3
4
5
namespace A
{
    // declaration of the function
    [[noreturn]] void foo( bool flag = true, double* = nullptr ) noexcept ; 
}


Type of the function: void( bool, double* ) noexcept

Signature of the function: ::A::foo( bool, double* )
Last edited on
He's asking about the prototype, not the type.
> He's asking about the prototype, not the type.

C101:
The declaration

int power(int base, int n);

just before main says that power is a function that expects two int arguments and returns an
int . This declaration, which is called a function prototype ...

- (K&R, Chapter 1)


There are two styles in which functions may be declared. In the new style, the types of
parameters are explicit and are part of the type of the function; such a declaration is also
called a function prototype.


- (K&R, Appendix A)


C++:
Function prototype scope

In a function declaration, or in any function declarator except the declarator of a function definition , names of parameters (if supplied) have function prototype scope, which terminates at the end of the nearest enclosing function declarator.

- IS


Compatibility with C:
Complete and consistent use of function declarations (function prototypes) is generally recommended for C. Where that sensible advice is followed, and especially where C compilers provide options to enforce it, C code conforms to the C++ rule.

- Stroustrup, TC++PL (fourth edition)
Last edited on
Hey thanks for reply but its really confusing one.

But what I mentioned is right then.

Signature not consider the return type of function, but prototype dose.

And Function declaration is same as its prototype.



> But what I mentioned is right then.

Yes.


> Signature not consider the return type of function, but prototype dose.

Yes.
Signature does not include the return type, (optional) parameter names, (optional) defaults for arguments, (optional) exception specification and (optional) attribute specifiers. It does include enclosing namespace (if any).
signature <function>
name, parameter type list, and enclosing namespace (if any)
[Note: Signatures are used as a basis for name mangling and linking.—end note ] - IS


> And Function declaration is same as its prototype.

Yes.

Function prototype is primarily a term used in C to distinguish between the two different kinds of function declarations; the classic C function declaration and the function declaration back-ported from C++. A C++ style function declaration in C is called a function prototype.
There are two styles in which functions may be declared. In the new style, the types of parameters are explicit and are part of the type of the function; such a declaration is also called a function prototype.

- (K&R, Appendix A)


(It was clear from your first post that you knew that, in C++, the terms function prototype and function declaration may be interchangeably used. My second post was for the edification of dhayden, who believed that the term 'function declaration' that I used in my post meant something quite different from the term 'function prototype' that you used in your first post.)
Last edited on
A function's signature is what differentiates it from other functions. You cannot have two functions with the same signature - they are considered the same function and you would get multiple definition errors. The return type is not part of the signature, as you already know.
Hey nice discussion I had with you guys.

Really thanks both of you JL and LB.

:)
Topic archived. No new replies allowed.