Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

inline variables

Use case

Header-only constants without ODR issues.

Explanation

inline variables can be defined in headers without causing multiple definition errors.

Code

#include "macho_constants.hpp"
#include <iostream>

int main() {
  std::cout << "64-bit magic: 0x" << std::hex << MH_MAGIC_64 << "\n";
  return 0;
}

View on GitHub.

Output

$ ./src/c++17/build/inline-variables
64-bit magic: 0xfeedfacf