Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 16
    I read your entire answer and I still don't get the semantic difference between static and static inline. Both of them make the definition invisible to other translation units. So what would be a sensible reason to write static inline instead of static? Commented Aug 4, 2020 at 23:20
  • 4
    +1 for the hugely insightful reminder that they are not useless, because they instruct the compiler to treat impossibility to do those optimizations as an error! Commented Sep 25, 2020 at 20:56
  • 3
    @user541686 The biggest and most important semantic difference is that static inline expresses your intent/approval for it to be inlined, whereas static does not. To be clear about definitions, "semantics" is basically a fancy word for "meaning", and so that is the most essential semantic difference right there. Because source code is first and foremost about describing what you intend for the code to do. And if you proactively intend for inlining to happen, you should say so, and inline is the most "native" way to say so in the language of C. Commented Sep 25, 2020 at 21:05
  • 1
    @jdk1-0 Intent is ideally communicated to both humans and software. Humans first and foremost, but the compiler and other tools can do a better job at optimizing or detecting problems if you can tell them your intent. So in the intent perspective, the difference between static inline and static INLINE_INTENT is that one of them also reveals your intent to compilers and other software (because we standardized on that as the way to express that specific intent). Commented May 21, 2021 at 17:25
  • 1
    Clang llvm uses a different threshold for inline specified functions: godbolt.org/z/rar9adfbv I dare say clang trunk is a "modern compiler" Commented Dec 11, 2021 at 23:14