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

Type aliases

Use case

Readable type names for binary analysis data structures.

Explanation

using aliases are more readable than typedef and work with templates.

Code

#include <cstdint>
#include <iostream>
#include <map>

using Address = uint64_t;
using Name = std::string;
using SymbolTable = std::map<Address, Name>;

int main() {
  SymbolTable symbols;
  // https://stackoverflow.com/questions/14788261/c-stdvector-emplace-vs-insert
  symbols.emplace(0x10001000, "_main");
  symbols.emplace(0x10002000, "_helper");

  std::cout << "Symbols:\n";
  for (const auto &s : symbols) {
    std::cout << "0x" << std::hex << s.first << ":" << s.second << "\n";
  }

  return 0;
}

View on GitHub.

Output

$ ./src/c++11/build/type-aliases
Symbols:
0x10001000:_main
0x10002000:_helper