Skip to content

Instantly share code, notes, and snippets.

@Adobe-Android
Last active September 17, 2020 17:22
Show Gist options
  • Save Adobe-Android/11083f695d618582efe3d5d27636c1eb to your computer and use it in GitHub Desktop.
Save Adobe-Android/11083f695d618582efe3d5d27636c1eb to your computer and use it in GitHub Desktop.
A comparison of int_fast and int_least at various guaranteed sizes (will vary based on system architecture and whether the program is 32 or 64-bit)
#include <iostream>
int main() {
// Optimizes for speed over memory use.
// On modern machines, int_fast16_t will often instead be 32-bit, consuming 4 bytes like
// int_fast32_t. This is actually better for performance.
std::cout << sizeof(int_fast16_t) << '\n';
std::cout << sizeof(int_fast32_t) << '\n';
std::cout << sizeof(int_fast64_t) << '\n';
// Optimizes for the smallest size (least amount of memory) that can guarantee the specified size.
std::cout << sizeof(int_least16_t) << '\n';
std::cout << sizeof(int_least32_t) << '\n';
std::cout << sizeof(int_least64_t) << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment