A header defines inline int sq(int n) { return n*n; } and two translation units include it. Why can the link step fail?
Correct answer
D. An inline definition is not an external definition, so no unit emits a callable body
13 views
D. An inline definition is not an external definition, so no unit emits a callable body
13 views
C99 inline gives an inline definition external linkage but no external definition, so if the compiler declines to inline every call the linker finds no symbol. Adding exactly one extern declaration, or writing static inline in the header, fixes it. C++ differs: an inline function may be defined in many units and the linker merges the duplicate definitions.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.