What does 'inline' mean?

Walter Bright newshound2 at digitalmars.com
Thu Jun 11 22:15:47 UTC 2020


On 6/11/2020 8:42 AM, kinke wrote:
> My interest in this wasn't triggered by wanting to enforce particular functions 
> to be emitted into each referencing CU, but by
> a) the current emission scheme requiring LTO in order to inline suited little 
> templated functions when compiling static libs in one go,
> b) being able to use linkonce_odr instead of weak_odr linkage for template 
> stuff, meaning potentially less work for the linker, and potentially quite a bit 
> less work for the optimizer. Compiling an optimized dub (a single object file) 
> with LDC using -linkonce-templates reduces the total compile+optimize times by 
> roughly 25%, simply because LLVM inlines most little template stuff and can then 
> discard the unused linkonce_odr functions early in the process, without 
> uselessly optimizing them to death (as it currently cannot discard it, as other 
> libraries/objects might depend on some template instances as mentioned earlier).

A library consists of two parts:

1. the "header" file
2. the binary to link with, which may be absent

Take some care in what goes in 1, what goes in 2, and you'll be fine.

For example, consider core.checkedint. The functions in it are all templates so 
that they can be used with -betterC which doesn't link with druntime. It's a 
classic "header only" library. It works fine.


More information about the Digitalmars-d mailing list