'namespace'에 해당되는 글 1건

  1. C++ Linkage specification 중 namespace 안의 extern "C"에 대해서.. 1

C++ Linkage specification 중 namespace 안의 extern "C"에 대해서..

ISO-IEC-14882(2003) 표준을 보면 다음과 같이 namespace안의 extern "C"에 대해 설명하고 있다.

At most one function with a particular name can have C language linkage.
Two declarations for a function with C language linkage with the same function name
(ignoring the namespace names that qualify it) that appear in different namespace scopes refer to the same function.
Two declarations for an object with C language linkage with the same name
(ignoring the  namespace names that qualify it) that appear in different namespace scopes refer to the same object.

[Note: because of the one definition rule (3.2),
only one definition for a function or object with C linkage may appear in the program;
that is, such a function or object must not be defined in more than one namespace scope.

For example,

namespace A {
extern "C" int f();
extern "C" int g() { return 1; }
extern "C" int h();
}
namespace B {
extern "C" int f();                                              // A::f and B::f refer
                                             // to the same function
extern "C" int g() { return 1; }                            // ill-formed, the function g
                     // with C language linkage
                     // has two definitions
}
int A::f() { return 98; }                                      // definition for the function f
                                // with C language linkage
extern "C" int h() { return 97; }
        // definition for the function h
        // with C language linkage
        // A::h and ::h refer to the same function

-end note]

한마디로 말해서 namespace를 무시하고 그냥 전역으로 보겠단 소리다.

근데 왜 이렇게 쓰는걸까?? 이렇게 쓰면 머가 좋지??

잘 모르겠다 그걸.... 역시 나의 지식은 무한히 짧구낭 ;;