In both C and C++, inline
functions with external linkage can of course have multiple definitions available at link-time, the assumption being that these definitions are all (hopefully) identical. (I am of course referring to functions declared with the inline
linkage specification, not to functions that the compiler or link-time-optimizer actually inlines.)
So what do common linkers typically do when they encounter multiple definitions of a function? In particular:
- Are all definitions included in the final executable or shared-library?
- Do all invocations of the function link against the same definition?
- Are the answers to the above questions required by one or more of the C and C++ ISO standards, and if not, do most common platforms do the same thing?
P.S. Yes, I know C and C++ are separate languages, but they both support inline
, and their compiler-output can typically be linked by the same linker (e.g. GCC's ld
), so I believe there cannot be any difference between them in this aspect.