kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

6_2_5_04_data_model_widths.c (1018B)


      1 #include <stddef.h>
      2 #include <stdint.h>
      3 
      4 _Static_assert(sizeof(long) == __SIZEOF_LONG__, "long width");
      5 _Static_assert(sizeof(unsigned long) == __SIZEOF_LONG__, "unsigned long width");
      6 _Static_assert(sizeof(size_t) == __SIZEOF_SIZE_T__, "size_t width");
      7 _Static_assert(sizeof(ptrdiff_t) == __SIZEOF_PTRDIFF_T__, "ptrdiff_t width");
      8 _Static_assert(sizeof(intptr_t) == __SIZEOF_POINTER__, "intptr_t width");
      9 _Static_assert(sizeof(uintptr_t) == __SIZEOF_POINTER__, "uintptr_t width");
     10 
     11 int test_main(void) {
     12   int a[2];
     13   int score = 0;
     14   if (sizeof(long) == __SIZEOF_LONG__) score += 1;
     15   if (sizeof(unsigned long) == __SIZEOF_LONG__) score += 2;
     16   if (sizeof(size_t) == __SIZEOF_SIZE_T__) score += 4;
     17   if (sizeof(ptrdiff_t) == __SIZEOF_PTRDIFF_T__) score += 8;
     18   if (sizeof(intptr_t) == __SIZEOF_POINTER__) score += 16;
     19   if (sizeof(uintptr_t) == __SIZEOF_POINTER__) score += 5;
     20   score += _Generic(sizeof(int), size_t: 3, default: 0);
     21   score += _Generic((&a[1] - &a[0]), ptrdiff_t: 3, default: 0);
     22   return score;
     23 }