> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C++ Inline Variable

An inline variable is a variable declared with the `inline` specifier, allowing it to be defined in multiple translation units without violating the One Definition Rule (ODR). Introduced in C++17, it instructs the linker to merge all identical definitions of the variable across different object files into a single, shared instance in memory. Crucially, if an inline variable is odr-used in a translation unit, a definition of that variable **must** be present in that exact translation unit (typically achieved by placing the definition in a shared header file).

## Syntax

```cpp theme={"dark"}
// Namespace scope
inline int global_counter = 0;

// Class scope (static data member)
struct Entity {
    inline static int entity_count = 0;
};
```

## Technical Mechanics

* **ODR Exemption and Requirement:** Standard variables defined in a header file and included in multiple `.cpp` files result in a multiple-definition linker error. The `inline` specifier exempts the variable from this strict ODR enforcement, permitting multiple definitions. However, it mandates that every translation unit that odr-uses the variable must contain its definition.
* **Linker Resolution:** When the linker encounters multiple definitions of an `inline` variable, it selects one definition and discards the others. All translation units referencing the variable will resolve to the exact same memory address.
* **Identical Definitions Requirement:** Every definition of the inline variable across all translation units must be token-for-token identical. If the definitions differ, the program is ill-formed, no diagnostic required (IFNDR), which results in undefined behavior.
* **Linkage:** Inline variables declared at namespace scope possess external linkage by default. They are visible across translation units unless explicitly marked `static` (which would force internal linkage, creating distinct, unshared instances per translation unit).
* **Initialization:** Dynamic initialization of an inline variable occurs exactly once. The initialization is sequenced before the first statement of `main`, or deferred until the variable is odr-used, depending on the implementation.

## Implicit Inline for `constexpr`

As of C++17, any `constexpr` static data member of a class is implicitly declared `inline`. It does not require a separate out-of-class definition to be odr-used (e.g., when its address is taken or it is bound to a reference).

```cpp theme={"dark"}
struct Configuration {
    // Implicitly inline in C++17+
    // No out-of-class definition (constexpr int Configuration::max_connections;) is needed
    static constexpr int max_connections = 50; 
};
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C++ Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
