www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Forcing inline functions (again) - groan

reply Cecil Ward <cecil cecilward.com> writes:
I recently noticed
     pragma(inline, true)
which looks extremely useful. A couple of questions :

1. Is this cross-compiler compatible?

2. Can I declare a function in one module and have it _inlined_ 
in another module at the call site?

I’m looking to write functions that expand to approx one or even 
zero machine instructions and having the overhead of a function 
call would be disastrous; in some cases would make it pointless 
having the function due to the slowdown.
Jul 15 2020
next sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote:
 I recently noticed
     pragma(inline, true)
 which looks extremely useful. A couple of questions :

 1. Is this cross-compiler compatible?

 2. Can I declare a function in one module and have it _inlined_ 
 in another module at the call site?

 I’m looking to write functions that expand to approx one or 
 even zero machine instructions and having the overhead of a 
 function call would be disastrous; in some cases would make it 
 pointless having the function due to the slowdown.
pragma inline will work for dmd. and it used to fail if it couldn't inline. Now it just generates a warning. So with -w it will still fail. Afaik other compilers cannot warn if the in-lining fails but I might be wrong. And ldc/gdc should be able to inline most code which makes sense to inline.
Jul 15 2020
prev sibling parent kinke <kinke gmx.net> writes:
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote:
 I recently noticed
     pragma(inline, true)
 which looks extremely useful. A couple of questions :

 1. Is this cross-compiler compatible?
Works for LDC and DMD, not sure about GDC, but if it doesn't support it, it's definitely on Iain's list.
 2. Can I declare a function in one module and have it _inlined_ 
 in another module at the call site?
For LDC, this works in all cases (i.e., also if compiling multiple object files in a single cmdline) since v1.22. While you cannot force LLVM to actually inline, I haven't come across a case yet where it doesn't.
Jul 15 2020