1 minute read

Were you always intrigued by inline, static, extern keywords in C++? Then look no further. This stackoverflow answer is as short and precise as it can be.

The following is a paraphrasing of the above linked answer:

  • Those three keywords are linkage directives for the linker and mostly ignored by the compiler.
  • inline: The linker will sort out multiple definitions of the same symbol (thus not to break the one-definition rule ODR). Especially it is not treated anymore as a hint to the compiler to optimize/inline the function call!
  • static: This SO answer describes it in more detail.
    • Variables: Their lifetime is extended throughout the programs runtime.
    • Class member functions: Can be called without an object.
    • Free-standing functions: Only callable from within that translation unit.
  • extern: Compiler need not know about the definition of a variable/function. Could be defined in a different translation unit or library. The linker will sort this out.

Tags:

Categories:

Updated: