Usefulness of Inline aspect nowadays

Wondering if the Inline aspect is any useful nowadays.
In C for example it is widely undestood to be mostly useless for its original stated purpose.

Thanks in advance,
– zen

Inline is a strange beast: it’s supposed to make your subprogram the equivalent of a macro, so-called “inline-expansion” — however, to strictly enforce this would make common attributes difficult/impossible to correctly handle (e.g. Some_Procedure'Address), unless the macro is not a text-expansion, but a thunk-site — which defeats the macro-expansion purpose.

See The RM link. / Not particularly helpful for the details of answering in this instance, but always a good idea to take a look.

I remember that in IBM C++ we used a macro and special *.inl files for inline to make sure there is aways a non inline version as well for code that needed are real version.

I was glad you don’t need to do that in Ada as it’s not really a macro. There is always a proper version as well for 'Access.

Anyway, I often use not both the Inline and Pure_Function aspects to give the compiler all the hints he needs for optimisation. Because that is what it really is: A compiler hint.

In GNAT there is the Inline aspect (as defined by the standard), but also the GNAT specific Inline_Always, which is less ambiguous.

Beyond that, in Ada 2022 the Static aspect was added to expression functions to let the compiler know more clearly that it can use those functions to compute static results (if the inputs are known at compile time). This is somewhat similar to constexpr in C++, it is a form of compile time evaluation. The Static functions may not be inlined, but instead, they will be entirely substituted with their precomputed values, which is even nicer.

Also, GCC supports different optimization profiles that may affect how Inline is treated. For example, for space constrained devices, functions may not be inlined. You could test this with the -Os optimization profile or the more extreme and less-well-known -Oz.

Best regards,
Fer

In a practical sense, I don’t know if it is useful. In a general sense it still is. There are still new chips being developed with a “what you see is what you get” type of architecture (no instruction or memory pipelines/caches). In those scenarios inline is a useful construct when you need to balance different types of manual optimization (speed vs size) in small scale embedded projects. I don’t think Ada targets any of these (hence the practical vs general), but GCC at least does (but no one has built an Ada cross compiler using the existing GCC build that targets them).

There is AVR-Ada | AdaCore which would be such an architecture, I guess.