Title
extern "C" functions and declarations in different namespaces
Status
nad
Section
9.11 [dcl.link]
Submitter
Erwin Unruh

Created on 1998-10-24.00:00:00 last changed 299 months ago

Messages

Date: 1999-04-15.00:00:00

Rationale (04/99): In 9.8.4 [namespace.udir] paragraph 4:

If name lookup finds a declaration for a name in two different namespaces, and the declarations do not declare the same entity and do not declare functions, the use of the name is ill-formed.
The term entity applied to typedefs refers to the underlying type or class (Clause 6 [basic] , paragraph 3); therefore both declarations of size_t declare the same entity and the above example is well-formed.

Date: 2022-02-18.07:47:23

Issue 1

9.11 [dcl.link] paragraph 6 says the following:

    extern "C" functions in multiple namespaces refer to the same function.
Is this only for linkage purposes or for both name look up and linkage purposes:
    extern "C" int f(void);
    namespace A {
         extern "C" int f(void);
    };
    using namespace A;

    int i = f(); // Ok because only one function f() or
                 // ill-formed
For name lookup, both declarations of f are visible and overloading cannot distinguish between them. Has the compiler to check that these functions are really the same function or is the program in error?

Rationale: These are the same function for all purposes.

Issue 2

A similar question may arise with typedefs:

    // vendor A
    typedef unsigned int size_t;
    // vendor B
    namespace std {
            typedef unsigned int size_t;
    }
    using namespace std;
    size_t something(); // error?
Is this valid because the typedef size_t refers to the same type in both namespaces?

Rationale (04/99): In 9.8.4 [namespace.udir] paragraph 4:

If name lookup finds a declaration for a name in two different namespaces, and the declarations do not declare the same entity and do not declare functions, the use of the name is ill-formed.
The term entity applied to typedefs refers to the underlying type or class (6.1 [basic.pre] paragraph 3); therefore both declarations of size_t declare the same entity and the above example is well-formed.

History
Date User Action Args
1999-09-14 00:00:00adminsetmessages: + msg195
1999-09-14 00:00:00adminsetstatus: drafting -> nad
1998-10-24 00:00:00admincreate