What are the linkage of the following functions?

Posted by Derui Si on Stack Overflow See other posts from Stack Overflow or by Derui Si
Published on 2012-09-04T03:30:59Z Indexed on 2012/09/04 3:38 UTC
Read the original article Hit count: 172

Filed under:

When I was reading the c++ 03 standard (7.1.1 Storage class specifiers [dcl.stc]), there are some examples as below, I'm not able to tell how the linkage of each successive declarations is determined? Could anyone help here? Thanks in advance!

static char* f();    // f() has internal linkage
char* f() 
       { /* ... */ } // f() still has internal linkage

char* g();           // g() has external linkage
static char* g() 
       { /* ... */ } // error: inconsistent linkage

void h();
inline void h(); // external linkage

inline void l();
void l(); // external linkage

inline void m();
extern void m(); // external linkage

static void n();
inline void n(); // internal linkage

static int a; // a has internal linkage
int a; // error: two definitions

static int b; // b has internal linkage
extern int b; // b still has internal linkage

int c; // c has external linkage
static int c; // error: inconsistent linkage

extern int d; // d has external linkage
static int d; // error: inconsistent linkage

UPD: Additionally, how can I understand the statement in the standard, "

The linkages implied by successive declarations for a given entity shall agree. That is, within a given scope, each declaration declaring the same object name or the same overloading of a function name shall imply the same linkage. Each function in a given set of overloaded functions can have a different linkage, however."

© Stack Overflow or respective owner

Related posts about c++