www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Something similar to "inline"

reply tososdk <elcahivo gmail.com> writes:
Two things: Could you explain how "inline" works? Is there 
something similar in Dlang?
Dec 27 2023
parent reply Paul Backus <snarwin gmail.com> writes:
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
parent Johan <j j.nl> writes:
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:
 Two things: Could you explain how "inline" works? Is there 
 something similar in Dlang?
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...
 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