@wallhackio You're the C++ standard knower, can you remind me what inline does? I forgot... I vaguely remember that it allows the same function to appear multiple times in the code, but doesn't necessarily make the compiler inline it? :psyduck:

Follow

@vaporeon_ its a hint to the compiler that you think a function should be "inlined" which means replacing any function invocations with the actual function body

this, theoretically, improves performance because you avoid the overhead of creating a stack. However, if a function is very lengthy, then inlining can increase the literal amount of machine instructions your program represents which might not be desirable. in general, inlining has the best chance of improving the performance of short functions that are called very often

The thing is, C++ compilers are allowed by the standard to inline functions even if they aren't given an inline command. And compilers are so damn smart nowadays that 99% of the time the compiler will automatically inline functions that get a performance benefit from being inlined. And the compiler may make the decision to not even inline a function you declare with inline if the compiler thinks it wouldn't make sense to do.

So the general advice in the modern day is not bother using the inline keyword at all unless you have profiled your program and identified a specific function as a throttle

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.