Return Type and Function Signature in C
In C , the return type of a function is not considered part of its signature for ordinary functions, meaning functions that are not specializations of function templates. This means that functions with the same name and parameter types can be overloaded, even if they have different return types.
Signature of Function Template Specializations
However, for function template specializations, the return type is included in the signature. This is because the signature of a function template specialization includes the signature of the template itself, as well as its return type and template parameter list.
Why is it Not Part of the Function Signature?
The reason why the return type is not considered part of the function signature for ordinary functions is not explicitly stated in the C Standard. However, it can be inferred that it is due to the fact that function overloading is primarily based on the function's identifier and parameter types.
When Overloading is Invalid
Despite the return type not being part of the signature, the Standard does forbid overloading a function with a different return type. This means that the following code will result in a compilation error in current major compilers:
int f(); double f(); // invalid
Conclusion
In C , the return type is not part of the signature of ordinary functions but is included in the signature of function template specializations. This distinction is important to understand when overloading functions and working with function templates.
The above is the detailed content of Is the Return Type Part of a C Function Signature?. For more information, please follow other related articles on the PHP Chinese website!