Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can reserved function names be overloaded?

This question is a follow-up question of this one.

Consider the following program:

#include <cmath>

// meaningless, only for language-lawyer purpose
void abs(void*) {}

int main(){
    abs(nullptr);
}

Does this program result in undefined behavior?


The related part in the standard is [extern.names]/4:

Each function signature from the C standard library declared with external linkage is reserved to the implementation for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope in the global namespace.

I'm not sure whether overloading is permitted.

like image 270
xskxzr Avatar asked Jun 19 '18 09:06

xskxzr


People also ask

Which of the following function type of function Cannot be overloaded?

2) Member function declarations with the same name and the name parameter-type-list cannot be overloaded if any of them is a static member function declaration.

Can functions have the same name?

Yes, it's called function overloading. Multiple functions are able to have the same name if you like, however MUST have different parameters.

When we use the same function name for more than one functions is called?

C++ lets you specify more than one function of the same name in the same scope. These functions are called overloaded functions, or overloads.

Which function Cannot be overloaded in C++ program virtual function member function static function all can be overloaded?

Q) Which function cannot be overloaded in C++ program? Static functions cannot be overloaded in C++ programming.


1 Answers

There are two parts to this statement, as it talks about names (from the C standard) that are reserved (for C++ implementations). In particular,

Part 1: Each function signature from the C standard library declared with external linkage

This includes the C library function abs

Part 2: is reserved to the implementation for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope in the global namespace.

So the name ::abs is reserved for the C++ implementation. You can't use it. Overloading is irrelevant.

like image 61
MSalters Avatar answered Sep 20 '22 16:09

MSalters