CKTIS / C++
inline — functions and variables defined in headers
inline allows function and variable definitions in headers while respecting the one-definition rule. It does not force call-site substitution or guarantee a faster program.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
inline int twice(int x) { return 2 * x; }
inline int counter = 0;
inline constexpr int limit = 10;inline does not force optimization. The compiler may retain an ordinary function call. The specifier cannot appear in a block-scope declaration or a parameter declaration.
In ordinary headers, outside named modules, inline functions and variables may have definitions in multiple translation units. However, the one-definition rule (ODR) requires the same token sequence and consistent name lookup, subject to standard-specified exceptions. Only one definition is still permitted within any single translation unit. A definition must be reachable where the ODR requires it; in practice, include a shared header. Macros that change the definition between files can violate the ODR without a required diagnostic.
Inline variables with external linkage denote one object with one address, not a separate copy in each file. inline alone means neither const nor constexpr: the example's counter is mutable. A constexpr function is implicitly inline, as is a static data member declared constexpr. An ordinary namespace-scope variable declared constexpr does not thereby become implicitly inline.
The example shows the function next() and variables counter and step. Successive calls print 2 and 4. A single file demonstrates syntax and state changes, but does not establish shared object identity across translation units. The supplied source is an evolving working draft, not a frozen C++23 edition.
Examples
#include <iostream>
inline int counter = 0;
inline constexpr int step = 2;
inline int next() {
counter += step;
return counter;
}
int main() {
std::cout << next() << '\n';
std::cout << next() << '\n';
}
Result
2 4
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.