Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 24428

re: Understanding the classical model for linking, groundwork: The algorithm

$
0
0

@Matt:

I'm not positive about this (there is conflicting information), but in C++, functions marked 'inline' still have external linkage. I didn't test, but from the MSDN docs it seems that MSVC is non-compliant in this regard (assuming that I'm correct). I also can't speak to __inline/__forceinline. This can arise if the compiler refuses to inline the function for some reason, or if the address of the function is taken: my understanding is that the address of even an inline function 'foo' is guaranteed to be the same across compilation units. For the same reasons that templates force 'selectany', so does this: the compiler must generate code for 'foo' in each compilation unit in which its address is taken, but it must merge those definitions at link time.

Even if the above is untrue for C++98/03, it is true in C++11.

In C, this is not true, and 'inline' functions have internal linkage.

However, I believe that even in MSVC there is a case where this occurs, which is member functions defined inline in a class ('class C { int random() { return 9; } };'). What the standard says about the linkage of *these* functions is much less conflicted, and they get external linkage -- and thus multiple definitions require collapsing duplicated symbols.


Viewing all articles
Browse latest Browse all 24428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>