digitalmars.D.learn - Something similar to "inline"
- tososdk (2/2) Dec 27 2023 Two things: Could you explain how "inline" works? Is there
- Paul Backus (13/15) Dec 27 2023 In C and C++, `inline` is a suggestion to the compiler that it
- Johan (9/17) Dec 27 2023 I don't think the D forums is the best place to ask about how
Two things: Could you explain how "inline" works? Is there something similar in Dlang?
Dec 27 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
Dec 27 2023
On Wednesday, 27 December 2023 at 16:35:47 UTC, Paul Backus wrote:On Wednesday, 27 December 2023 at 15:57:14 UTC, tososdk wrote:I don't think the D forums is the best place to ask about how "inline" works, when you mean another "inline" than what is available in D...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`.`inline` in C/C++ is only vaguely related to inline expansion. Its meaning is related to linkage, allowing multiple definitions of that symbol. https://en.cppreference.com/w/cpp/language/inline Dlang does not have something similar. -Johan
Dec 27 2023