Skip to content

Instantly share code, notes, and snippets.

@rangerz
Last active March 14, 2016 02:54
Show Gist options
  • Save rangerz/0dd49ef21cd8a612bb3b to your computer and use it in GitHub Desktop.
Save rangerz/0dd49ef21cd8a612bb3b to your computer and use it in GitHub Desktop.
[C++] build-in type size and range
#include<iostream>
#include<iomanip>
#include<string>
#include<limits>
using namespace std;
#define SIZEOF(x) cout << \
setw(24) << #x << \
setw(9) << sizeof(x) << \
setw(21) << (numeric_limits<x>::max)() << \
setw(21) << (numeric_limits<x>::min)() << endl
#define SERIES(x) cout << endl << \
setw(24) << "[" #x "]" << endl;
int main()
{
cout << \
setw(24) << "type" << \
setw(9) << "sizeof()" << \
setw(21) << "max" << \
setw(21) << "min" << endl;
cout << "Boolean type:" << endl;
SIZEOF(bool);
cout << endl << "Character types:" << endl;
SIZEOF(char);
SIZEOF(unsigned char);
SIZEOF(signed char);
SIZEOF(wchar_t);
SIZEOF(char16_t);
SIZEOF(char32_t);
cout << endl << "Integer types:" << endl;
SIZEOF(int);
SIZEOF(signed);
SIZEOF(unsigned);
SIZEOF(short);
SIZEOF(long);
SIZEOF(long long);
SERIES(short int);
SIZEOF(short);
SIZEOF(short int);
SIZEOF(signed short);
SIZEOF(signed short int);
SERIES(unsigned short int);
SIZEOF(unsigned short);
SIZEOF(unsigned short int);
SERIES(int);
SIZEOF(int);
SIZEOF(signed);
SIZEOF(signed int);
SERIES(unsigned int);
SIZEOF(unsigned);
SIZEOF(unsigned int);
SERIES(long int);
SIZEOF(long);
SIZEOF(long int);
SIZEOF(signed long);
SIZEOF(signed long int);
SERIES(long long int);
SIZEOF(long long);
SIZEOF(long long int);
SIZEOF(signed long long);
SIZEOF(signed long long int);
SERIES(unsigned long long int);
SIZEOF(unsigned long long);
SIZEOF(unsigned long long int);
cout << endl << "Floating point types:" << endl;
SIZEOF(float);
SIZEOF(double);
SIZEOF(long double);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment