Zero-cost version-dependent function call at -O0.

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 25 15:23:44 PDT 2017


On Sunday, 25 June 2017 at 21:55:22 UTC, Johan Engelen wrote:
> On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote:
>>
>> By requiring the compiler to inline the empty foo:
>
> This won't work.

Yes, it does; comment out the call to `foo` and notice no change 
in the assembly in my link.

> Semantically, there is still a call

You asked for

> no call and no extra code at -O0

and that is exactly what this solution provides.

> and e.g. profiling will see it:
> https://godbolt.org/g/AUCeuu

The solution obviously does *not* work if you change the premise 
of your question after the fact by artificially injecting 
instructions into all function bodies (read what 
`-finstrument-functions` does).


More information about the Digitalmars-d-learn mailing list