Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In this answer https://stackoverflow.com/a/4193698/738811 it's written that "Inline functions by default have external linkage". However it's not possible by default to link against something what is inline. So what's the sense to say that inline functions have external linkage?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
361 views
Welcome To Ask or Share your Answers For Others

1 Answer

The linkage of a name has nothing to do with where or how it is defined, just with where the name may be used to refer to a particular object or function.

Declaring a function inline does not force it to be inlined; it just relaxes the One Definition Rule to allow a definition in each translation unit in which it's used (and require one in each translation unit in which it's called), to make it easier to inline. It doesn't prevent a non-inline version being generated, if the compiler decides not to inline a particular call to it, or if you take the address of it.

So "external linkage" and "inline" are not exclusive; "external linkage" means that the function may be referred to in any translation unit, and "inline" means that it must be defined in any translation unit that calls it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...