Search code examples
inlineadapragmagnat

Can I put pragma `Inline` in the body instead of the spec?


Ada Information Clearinghouse states the following:

The use of pragma Inline does have its disadvantages. It can create compilation dependencies on the body; that is, when the specification uses a pragma Inline, both the specification and corresponding body may need to be compiled before the specification can be used.

Does putting pragma Inline in the body avoid this problem?


Solution

  • The advantage is that Inline in the specification allows for cross-unit inlining which can be a very powerful run-time optimization.

    The disadvantage you mention matters rather when you compile on a computer which is slow or has few cores. Then it's a run time vs compile time trade-off.

    Note that on GNAT, cross-unit inlining is enabled by a single switch (-gnatn), so don't be afraid by the Inline pragma creating compilation dependencies: you can switch the whole mechanism on or off with that switch.