On Mon, Apr 3, 2017 at 10:02 AM, Liu Hao <[email protected]> wrote:

> On 2017/4/4 0:48, David Grayson wrote:
> > I'm a bit confused about the different inlining keywords.  From the GCC
> > documentation for inlining in the C language (
> > https://gcc.gnu.org/onlinedocs/gcc/Inline.html ) it seemed like "extern
> > inline" (i.e. __CRT_INLINE) would be the best thing to use, but I could
> not
> > find any cases where __inline (which I think is a macro) is worse.
> > LH_Mouse's patch does not change what kind of inlining keywords are used,
> > it just changes the logic for when to use those keywords.
> If you have multiple `extern inline` definitions in different
> translation units (TU), a C++ compiler is smart enough to mark them as
> 'link once', so the linker will only pick the first definition it finds
> and discard the rest. This isn't the case in C. If you have an `extern
> inline` function _defined_ in a header, the definition would end up in
> every TU that refers that header, resulting in multiple definitions of
> that function.


What you say matches what I got from my experiments, but it's odd that it
doesn't match the GCC documentation I linked to, which says:

  If you specify both inline and extern in the function definition, then
the definition is used only for inlining. In no case is the function
compiled on its own, not even if you refer to its address explicitly. Such
an address becomes an external reference, as if you had only declared the
function, and had not defined it.

So it's saying that the TUs might have references to an external function
but they will not contain globally-visible definitions that could cause a
multiple definition error.  There must be something I am missing, but it's
OK.

--David
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to