c++ - What do linkers actually do with multiply-defined `inline` functions? -
in both c , c++, inline
functions external linkage can of course have multiple definitions available @ link-time, assumption being these definitions (hopefully) identical. (i of course referring functions declared inline
linkage specification, not functions compiler or link-time-optimizer inlines.)
so common linkers typically do when encounter multiple definitions of function? in particular:
- are definitions included in final executable or shared-library?
- do invocations of function link against same definition?
- are answers above questions required 1 or more of c , c++ iso standards, , if not, common platforms same thing?
p.s. yes, know c , c++ separate languages, both support inline
, , compiler-output can typically linked same linker (e.g. gcc's ld
), believe there cannot difference between them in aspect.
the linker has figure out how deduplicate definitions. of course provided function definitions have been emitted @ all; inline functions may inlined. should take address of inline function external linkage, same address (cf. [dcl.fct.spec]/4).
inline functions aren't construction require linker support; templates another, inline variables (in c++17).
Comments
Post a Comment