Something similar to "inline"
Paul Backus
snarwin at gmail.com
Wed Dec 27 16:35:47 UTC 2023
On Wednesday, 27 December 2023 at 15:57:14 UTC, tososdk wrote:
> Two things: Could you explain how "inline" works? Is there
> something similar in Dlang?
In C and C++, `inline` is a suggestion to the compiler that it
should consider using [inline expansion][1] for calls to a
particular function. However, the compiler is free to ignore this
suggestion, and is also free to use inline expansion for
functions that are not marked with `inline`.
In D, the closest equivalent is [`pragma(inline)`][2], which can
be used to enable or disable inline expansion for a particular
function. With `pragma(inline, true)`, the function will *always*
be expanded inline; with `pragma(inline, false)`, it will *never*
be expanded.
[1]: https://en.wikipedia.org/wiki/Inline_expansion
[2]: https://dlang.org/spec/pragma.html#inline
More information about the Digitalmars-d-learn
mailing list