Skip to content

Instantly share code, notes, and snippets.

@ookiineko
Last active November 15, 2022 15:33
Show Gist options
  • Save ookiineko/c3c234c25a2aa4cea2754fab8c907b92 to your computer and use it in GitHub Desktop.
Save ookiineko/c3c234c25a2aa4cea2754fab8c907b92 to your computer and use it in GitHub Desktop.
type test
#include <stdio.h>
#include <stddef.h>
int main() {
printf("align is %ld.\n", __alignof__(max_align_t));
printf("count is %ld.\n", sizeof(max_align_t) / 8); // 8 stands for f64
return 0;
}
#include <stdio.h>
int main() {
printf("pointer width is %ld.\n", sizeof(void*) * 8);
return 0;
}
#include <iostream>
#include <limits>
using namespace std;
template <typename T> struct test_int {
test_int(const char* name) {
cout << name << ": ";
cout << (numeric_limits<T>::is_signed ? "i" : "u");
cout << sizeof(T) * 8 << "." << endl;
}
};
template <typename T> struct test_float {
test_float(const char* name) {
cout << name << ": f" << sizeof(T) * 8 << "." << endl;
}
};
int main() {
test_int<char>{"c_char"};
test_int<unsigned char>{"c_uchar"};
test_int<short>{"c_short"};
test_int<unsigned short>{"c_ushort"};
test_int<int>{"c_int"};
test_int<unsigned int>{"c_uint"};
test_int<long>{"c_long"};
test_int<unsigned long>{"c_ulong"};
test_int<long long>{"c_longlong"};
test_int<unsigned long long>{"c_ulonglong"};
test_float<float>{"c_float"};
test_float<double>{"c_double"};
test_float<long double>{"c_longdouble"};
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment