pragma(inline, true) errors?

tsbockman thomas.bockman at gmail.com
Thu Apr 1 19:13:56 UTC 2021


On Thursday, 1 April 2021 at 18:38:45 UTC, Steven Schveighoffer 
wrote:
> Here is a relevant run.dlang.io snippet: 
> https://run.dlang.io/is/UEtyE8
>
> Some interesting things about this:
>
> 1. With -w, I get no errors.
> 2. With -wi, I get a warning that the function can be inlined
> 3. Using ASM view, it appears the function is NOT inlined in 
> either case.

DMD's inliner often gets confused by multiple `return` 
statements. The solution is to either convert to single-`return` 
style, or use LDC/GDC which do not have this problem.

```D
extern(C) pragma(inline, true) static float EaseBounceOut(float 
t, float b, float c, float d)
{
     float ret;
     if ((t/=d) < (1.0f/2.75f))
     {
         ret = (c*(7.5625f*t*t) + b);
     }
     else if (t < (2.0f/2.75f))
     {
         float postFix = t-=(1.5f/2.75f);
         ret = (c*(7.5625f*(postFix)*t + 0.75f) + b);
     }
     else if (t < (2.5/2.75))
     {
         float postFix = t-=(2.25f/2.75f);
         ret = (c*(7.5625f*(postFix)*t + 0.9375f) + b);
     }
     else
     {
         float postFix = t-=(2.625f/2.75f);
         ret = (c*(7.5625f*(postFix)*t + 0.984375f) + b);
     }
     return ret;
}
```

(I have no comment on the larger issues that you raised. Also, 
hurray for rich text formatting!)


More information about the Digitalmars-d mailing list