alansam

Primitive type sizes.

Oct 7th, 2020
1,120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main() {
  2.   typedef
  3.   struct fv {
  4.     char name[20];
  5.     size_t sz;
  6.   } fv;
  7.   fv types[] = {
  8.     { "char",         sizeof(char), },
  9.     { "short",        sizeof(short), },
  10.     { "int",          sizeof(int), },
  11.     { "long",         sizeof(long), },
  12.     { "long long",    sizeof(long long), },
  13.     { "float",        sizeof(float), },
  14.     { "double",       sizeof(double), },
  15.     { "long double",  sizeof(long double), },
  16.   };
  17.   size_t types_s = sizeof(types);
  18.   size_t types_e = types_s / sizeof(*types);
  19.  
  20.   for (size_t e_ = 0; e_ < types_e; ++e_) {
  21.     char * name = types[e_].name;
  22.     size_t size = types[e_].sz;
  23.     printf("size of %16s %2zu\n", name, size);
  24.   }
  25.   return 0;
  26. }
  27.  
RAW Paste Data