简体   繁体   中英

linkage of function with parameter from unnamed namespace

namespace { class A { } ; }

void foo ( A ) // _Z3fooN12_GLOBAL__N_11AE
{ ; } 

the function's symbol, apparently, would refer to the name of A, which is a member of uniquely named namespace (due to this ).

what is the foo's linkage.?

The function foo has external linkage since it is global and not declared static . The linkage of a function doesn't depend on the parameters.

The fact that A has internal linkage implies that it is not possible to call foo from another translation unit, since it is impossible to declare foo in the other translation unit, since there is no way to write the name of the type of foo 's parameter. Any attempt to define A in another translation unit will actually define a different type.

Therefore, while the name foo technically has external linkage, it cannot actually be referred to by other translation units.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM