(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
stdint-width-2.c
       1  /* Test C2X width macros in <stdint.h>.  */
       2  /* { dg-do compile } */
       3  /* { dg-options "-std=c2x -ffreestanding" } */
       4  /* { dg-additional-options "-DSIGNAL_SUPPRESS" { target { ! signal } } } */
       5  
       6  #include <stddef.h>
       7  #include <stdint.h>
       8  #ifndef SIGNAL_SUPPRESS
       9  #include <signal.h>
      10  #endif
      11  typedef __WINT_TYPE__ wint_t;
      12  
      13  #define CHECK_WIDTH(TYPE, MAX, WIDTH)					\
      14    _Static_assert ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) == 1, \
      15  		  "width must match type")
      16  
      17  #ifdef INT8_MAX
      18  # ifndef INT8_WIDTH
      19  #  error "missing INT8_WIDTH"
      20  # endif
      21  CHECK_WIDTH (int8_t, INT8_MAX, INT8_WIDTH);
      22  #endif
      23  #ifdef INT16_MAX
      24  # ifndef INT16_WIDTH
      25  #  error "missing INT16_WIDTH"
      26  # endif
      27  CHECK_WIDTH (int16_t, INT16_MAX, INT16_WIDTH);
      28  #endif
      29  #ifdef INT32_MAX
      30  # ifndef INT32_WIDTH
      31  #  error "missing INT32_WIDTH"
      32  # endif
      33  CHECK_WIDTH (int32_t, INT32_MAX, INT32_WIDTH);
      34  #endif
      35  #ifdef INT64_MAX
      36  # ifndef INT64_WIDTH
      37  #  error "missing INT64_WIDTH"
      38  # endif
      39  CHECK_WIDTH (int64_t, INT64_MAX, INT64_WIDTH);
      40  #endif
      41  #ifdef UINT8_MAX
      42  # ifndef UINT8_WIDTH
      43  #  error "missing UINT8_WIDTH"
      44  # endif
      45  CHECK_WIDTH (uint8_t, UINT8_MAX, UINT8_WIDTH);
      46  #endif
      47  #ifdef UINT16_MAX
      48  # ifndef UINT16_WIDTH
      49  #  error "missing UINT16_WIDTH"
      50  # endif
      51  CHECK_WIDTH (uint16_t, UINT16_MAX, UINT16_WIDTH);
      52  #endif
      53  #ifdef UINT32_MAX
      54  # ifndef UINT32_WIDTH
      55  #  error "missing UINT32_WIDTH"
      56  # endif
      57  CHECK_WIDTH (uint32_t, UINT32_MAX, UINT32_WIDTH);
      58  #endif
      59  #ifdef UINT64_MAX
      60  # ifndef UINT64_WIDTH
      61  #  error "missing UINT64_WIDTH"
      62  # endif
      63  CHECK_WIDTH (uint64_t, UINT64_MAX, UINT64_WIDTH);
      64  #endif
      65  
      66  #ifndef INT_LEAST8_WIDTH
      67  # error "missing INT_LEAST8_WIDTH"
      68  #endif
      69  CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX, INT_LEAST8_WIDTH);
      70  #ifndef INT_LEAST16_WIDTH
      71  # error "missing INT_LEAST16_WIDTH"
      72  #endif
      73  CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX, INT_LEAST16_WIDTH);
      74  #ifndef INT_LEAST32_WIDTH
      75  # error "missing INT_LEAST32_WIDTH"
      76  #endif
      77  CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX, INT_LEAST32_WIDTH);
      78  #ifndef INT_LEAST64_WIDTH
      79  # error "missing INT_LEAST64_WIDTH"
      80  #endif
      81  CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX, INT_LEAST64_WIDTH);
      82  #ifndef INT_LEAST8_WIDTH
      83  # error "missing INT_LEAST8_WIDTH"
      84  #endif
      85  CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX, UINT_LEAST8_WIDTH);
      86  #ifndef UINT_LEAST16_WIDTH
      87  # error "missing UINT_LEAST16_WIDTH"
      88  #endif
      89  CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX, UINT_LEAST16_WIDTH);
      90  #ifndef UINT_LEAST32_WIDTH
      91  # error "missing UINT_LEAST32_WIDTH"
      92  #endif
      93  CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX, UINT_LEAST32_WIDTH);
      94  #ifndef UINT_LEAST64_WIDTH
      95  # error "missing UINT_LEAST64_WIDTH"
      96  #endif
      97  CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX, UINT_LEAST64_WIDTH);
      98  
      99  #ifndef INT_FAST8_WIDTH
     100  # error "missing INT_FAST8_WIDTH"
     101  #endif
     102  CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX, INT_FAST8_WIDTH);
     103  #ifndef INT_FAST16_WIDTH
     104  # error "missing INT_FAST16_WIDTH"
     105  #endif
     106  CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX, INT_FAST16_WIDTH);
     107  #ifndef INT_FAST32_WIDTH
     108  # error "missing INT_FAST32_WIDTH"
     109  #endif
     110  CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX, INT_FAST32_WIDTH);
     111  #ifndef INT_FAST64_WIDTH
     112  # error "missing INT_FAST64_WIDTH"
     113  #endif
     114  CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX, INT_FAST64_WIDTH);
     115  #ifndef INT_FAST8_WIDTH
     116  # error "missing INT_FAST8_WIDTH"
     117  #endif
     118  CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX, UINT_FAST8_WIDTH);
     119  #ifndef UINT_FAST16_WIDTH
     120  # error "missing UINT_FAST16_WIDTH"
     121  #endif
     122  CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX, UINT_FAST16_WIDTH);
     123  #ifndef UINT_FAST32_WIDTH
     124  # error "missing UINT_FAST32_WIDTH"
     125  #endif
     126  CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX, UINT_FAST32_WIDTH);
     127  #ifndef UINT_FAST64_WIDTH
     128  # error "missing UINT_FAST64_WIDTH"
     129  #endif
     130  CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX, UINT_FAST64_WIDTH);
     131  
     132  #ifdef INTPTR_MAX
     133  # ifndef INTPTR_WIDTH
     134  #  error "missing INTPTR_WIDTH"
     135  # endif
     136  CHECK_WIDTH (intptr_t, INTPTR_MAX, INTPTR_WIDTH);
     137  #endif
     138  #ifdef UINTPTR_MAX
     139  # ifndef UINTPTR_WIDTH
     140  #  error "missing UINTPTR_WIDTH"
     141  # endif
     142  CHECK_WIDTH (uintptr_t, UINTPTR_MAX, UINTPTR_WIDTH);
     143  #endif
     144  
     145  #ifndef INTMAX_WIDTH
     146  # error "missing INTMAX_WIDTH"
     147  #endif
     148  CHECK_WIDTH (intmax_t, INTMAX_MAX, INTMAX_WIDTH);
     149  #ifndef UINTMAX_WIDTH
     150  # error "missing UINTMAX_WIDTH"
     151  #endif
     152  CHECK_WIDTH (uintmax_t, UINTMAX_MAX, UINTMAX_WIDTH);
     153  
     154  #ifndef PTRDIFF_WIDTH
     155  # error "missing PTRDIFF_WIDTH"
     156  #endif
     157  CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX, PTRDIFF_WIDTH);
     158  #ifndef SIGNAL_SUPPRESS
     159  # ifndef SIG_ATOMIC_WIDTH
     160  #  error "missing SIG_ATOMIC_WIDTH"
     161  # endif
     162  CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX, SIG_ATOMIC_WIDTH);
     163  #endif
     164  #ifndef SIZE_WIDTH
     165  # error "missing SIZE_WIDTH"
     166  #endif
     167  CHECK_WIDTH (size_t, SIZE_MAX, SIZE_WIDTH);
     168  #ifndef WCHAR_WIDTH
     169  # error "missing WCHAR_WIDTH"
     170  #endif
     171  CHECK_WIDTH (wchar_t, WCHAR_MAX, WCHAR_WIDTH);
     172  #ifndef WINT_WIDTH
     173  # error "missing WINT_WIDTH"
     174  #endif
     175  CHECK_WIDTH (wint_t, WINT_MAX, WINT_WIDTH);