root/maint/gnulib/tests/test-limits-h.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of <limits.h> substitute.
   2    Copyright 2016-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Paul Eggert.  */
  18 
  19 #include <config.h>
  20 
  21 #include <limits.h>
  22 
  23 #include "verify.h"
  24 
  25 #if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
  26 # pragma GCC diagnostic ignored "-Woverlength-strings"
  27 #endif
  28 
  29 #define verify_width(width, min, max) \
  30   verify ((max) >> ((width) - 1 - ((min) < 0)) == 1)
  31 
  32 /* Macros borrowed from intprops.h.  */
  33 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
  34 #define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
  35 #define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
  36 #define TYPE_MAXIMUM(t)                                                 \
  37   ((t) (! TYPE_SIGNED (t)                                               \
  38         ? (t) -1                                                        \
  39         : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
  40 
  41 /* Type width macros.  */
  42 
  43 int type_bits[] =
  44   {
  45     CHAR_BIT,
  46     WORD_BIT,
  47     LONG_BIT
  48   };
  49 verify_width (CHAR_BIT, CHAR_MIN, CHAR_MAX);
  50 verify_width (WORD_BIT, INT_MIN, INT_MAX);
  51 verify_width (LONG_BIT, LONG_MIN, LONG_MAX);
  52 
  53 /* Numerical limit macros.  */
  54 
  55 char               limits1[]  = { CHAR_MIN, CHAR_MAX };
  56 verify (TYPE_MINIMUM (char) == CHAR_MIN);
  57 verify (TYPE_MAXIMUM (char) == CHAR_MAX);
  58 
  59 signed char        limits2[]  = { SCHAR_MIN, SCHAR_MAX };
  60 verify (TYPE_MINIMUM (signed char) == SCHAR_MIN);
  61 verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX);
  62 
  63 unsigned char      limits3[]  = { UCHAR_MAX };
  64 verify (TYPE_MINIMUM (unsigned char) == 0);
  65 verify (TYPE_MAXIMUM (unsigned char) == UCHAR_MAX);
  66 
  67 short              limits4[]  = { SHRT_MIN, SHRT_MAX };
  68 verify (TYPE_MINIMUM (short int) == SHRT_MIN);
  69 verify (TYPE_MAXIMUM (short int) == SHRT_MAX);
  70 
  71 unsigned short     limits5[]  = { USHRT_MAX };
  72 verify (TYPE_MINIMUM (unsigned short int) == 0);
  73 verify (TYPE_MAXIMUM (unsigned short int) == USHRT_MAX);
  74 
  75 int                limits6[]  = { INT_MIN, INT_MAX };
  76 verify (TYPE_MINIMUM (int) == INT_MIN);
  77 verify (TYPE_MAXIMUM (int) == INT_MAX);
  78 
  79 unsigned int       limits7[]  = { UINT_MAX };
  80 verify (TYPE_MINIMUM (unsigned int) == 0);
  81 verify (TYPE_MAXIMUM (unsigned int) == UINT_MAX);
  82 
  83 long               limits8[]  = { LONG_MIN, LONG_MAX };
  84 verify (TYPE_MINIMUM (long int) == LONG_MIN);
  85 verify (TYPE_MAXIMUM (long int) == LONG_MAX);
  86 
  87 unsigned long      limits9[]  = { ULONG_MAX };
  88 verify (TYPE_MINIMUM (unsigned long int) == 0);
  89 verify (TYPE_MAXIMUM (unsigned long int) == ULONG_MAX);
  90 
  91 long long          limits10[] = { LLONG_MIN, LLONG_MAX };
  92 verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
  93 verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
  94 
  95 unsigned long long limits11[] = { ULLONG_MAX };
  96 verify (TYPE_MINIMUM (unsigned long long int) == 0);
  97 verify (TYPE_MAXIMUM (unsigned long long int) == ULLONG_MAX);
  98 
  99 /* Macros specified by ISO/IEC TS 18661-1:2014.  */
 100 
 101 verify_width (CHAR_WIDTH, CHAR_MIN, CHAR_MAX);
 102 verify_width (SCHAR_WIDTH, SCHAR_MIN, SCHAR_MAX);
 103 verify_width (UCHAR_WIDTH, 0, UCHAR_MAX);
 104 verify_width (SHRT_WIDTH, SHRT_MIN, SHRT_MAX);
 105 verify_width (USHRT_WIDTH, 0, USHRT_MAX);
 106 verify_width (INT_WIDTH, INT_MIN, INT_MAX);
 107 verify_width (UINT_WIDTH, 0, UINT_MAX);
 108 verify_width (LONG_WIDTH, LONG_MIN, LONG_MAX);
 109 verify_width (ULONG_WIDTH, 0, ULONG_MAX);
 110 verify_width (LLONG_WIDTH, LLONG_MIN, LLONG_MAX);
 111 verify_width (ULLONG_WIDTH, 0, ULLONG_MAX);
 112 
 113 /* Macros specified by C2x.  */
 114 
 115 int bool_attrs[] = { BOOL_MAX, BOOL_WIDTH };
 116 verify (BOOL_MAX == (((1U << (BOOL_WIDTH - 1)) - 1) * 2) + 1);
 117 
 118 int
 119 main (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121   return 0;
 122 }

/* [previous][next][first][last][top][bottom][index][help] */