Created
November 13, 2019 12:24
-
-
Save KisaragiEffective/425b10dd872adbb7c9a737908f3a4ad4 to your computer and use it in GitHub Desktop.
64ビットデータモデル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file is LICENSED WITH https://gist.github.com/KisaragiEffective/a0aba5fd0ed0ab7c5839a5cb3038b9bc | |
using namespace std; | |
#include <iostream> | |
#include <limits> | |
template <class T> | |
constexpr int bits(T t) { | |
return std::numeric_limits<T>::digits; | |
} | |
constexpr bool is_LP64() { | |
return bits(static_cast<unsigned int>(1)) == 32 | |
&& bits(static_cast<unsigned long>(1)) == 64 | |
&& sizeof(int*) == 8; | |
} | |
constexpr bool is_ILP64() { | |
return bits(static_cast<unsigned int>(1)) == 64 | |
&& bits(static_cast<unsigned long>(1)) == 64 | |
&& sizeof(int*) == 8; | |
} | |
constexpr bool is_LLP64() { | |
return bits(static_cast<unsigned int>(1)) == 32 | |
&& bits(static_cast<unsigned long>(1)) == 32 | |
&& bits(static_cast<unsigned long long>(1)) == 64 | |
&& sizeof(int*) == 8; | |
} | |
template <class T> | |
constexpr long bytes() { | |
return sizeof(T); | |
} | |
int main() { | |
cout << "LP64?: " << is_LP64() << endl; | |
cout << "ILP64?: " << is_ILP64() << endl; | |
cout << "LLP64?: " << is_LLP64() << endl; | |
cout << "sizeof<long>:" << bytes<long>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment