0

I know what is static keyword means for functions. But I cant understand what is inline keyword means for function. I know that inline function is a function that is expanded in line when it is called. But inline its offer for compiler, he can ignore it. And perhaps compiler can optimize some functions and make it inline.

1) So why I need to declare functions inline, if compiler know better than me when need to function be inline, and when not ?

2) And I know inline functions have "external linkage" or something like that. what its mean ?

3) Does it make sense declare some functions inline static ?

CErjk
  • 11
  • 2
  • A very good piece of information about inline can be found here : https://stackoverflow.com/questions/1759300/when-should-i-write-the-keyword-inline-for-a-function-method – Theodor Badea Nov 18 '19 at 15:13

1 Answers1

1

The inline keyword is required to prevent violations of ODR (One Definition Rule). It doesn't relate to whether the function is actually inlined by the compiler, it merely tells the compiler that a definition is required in every translation unit.

With regards to "external linkage", this allows a static variable within an inline function to be shared across all translation units (which you would expect). If inline functions had "internal linkage" then each copy of the function (in each translation unit) would end up with it's own instance of the static variable, which wouldn't make much sense.

Mark Ingram
  • 71,849
  • 51
  • 176
  • 230