Blame stdlib/tst-width-stdint.c

Packit 6c4009
/* Test integer width macros in <stdint.h>.
Packit 6c4009
   Copyright (C) 2016-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <signal.h>
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <wchar.h>
Packit 6c4009
Packit 6c4009
#define CHECK_WIDTH(TYPE, MAX, WIDTH)					\
Packit 6c4009
  do									\
Packit 6c4009
    {									\
Packit 6c4009
      if ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) != 1)	\
Packit 6c4009
	{								\
Packit 6c4009
	  puts ("bad width of " #TYPE);					\
Packit 6c4009
	  result = 1;							\
Packit 6c4009
	}								\
Packit 6c4009
      else								\
Packit 6c4009
	puts ("width of " #TYPE " OK");					\
Packit 6c4009
    }									\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int result = 0;
Packit 6c4009
Packit 6c4009
#ifndef INT8_WIDTH
Packit 6c4009
# error "missing INT8_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int8_t, INT8_MAX, INT8_WIDTH);
Packit 6c4009
#ifndef INT16_WIDTH
Packit 6c4009
# error "missing INT16_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int16_t, INT16_MAX, INT16_WIDTH);
Packit 6c4009
#ifndef INT32_WIDTH
Packit 6c4009
# error "missing INT32_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int32_t, INT32_MAX, INT32_WIDTH);
Packit 6c4009
#ifndef INT64_WIDTH
Packit 6c4009
# error "missing INT64_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int64_t, INT64_MAX, INT64_WIDTH);
Packit 6c4009
#ifndef UINT8_WIDTH
Packit 6c4009
# error "missing UINT8_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint8_t, UINT8_MAX, UINT8_WIDTH);
Packit 6c4009
#ifndef UINT16_WIDTH
Packit 6c4009
# error "missing UINT16_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint16_t, UINT16_MAX, UINT16_WIDTH);
Packit 6c4009
#ifndef UINT32_WIDTH
Packit 6c4009
# error "missing UINT32_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint32_t, UINT32_MAX, UINT32_WIDTH);
Packit 6c4009
#ifndef UINT64_WIDTH
Packit 6c4009
# error "missing UINT64_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint64_t, UINT64_MAX, UINT64_WIDTH);
Packit 6c4009
Packit 6c4009
#ifndef INT_LEAST8_WIDTH
Packit 6c4009
# error "missing INT_LEAST8_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX, INT_LEAST8_WIDTH);
Packit 6c4009
#ifndef INT_LEAST16_WIDTH
Packit 6c4009
# error "missing INT_LEAST16_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX, INT_LEAST16_WIDTH);
Packit 6c4009
#ifndef INT_LEAST32_WIDTH
Packit 6c4009
# error "missing INT_LEAST32_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX, INT_LEAST32_WIDTH);
Packit 6c4009
#ifndef INT_LEAST64_WIDTH
Packit 6c4009
# error "missing INT_LEAST64_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX, INT_LEAST64_WIDTH);
Packit 6c4009
#ifndef UINT_LEAST8_WIDTH
Packit 6c4009
# error "missing UINT_LEAST8_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX, UINT_LEAST8_WIDTH);
Packit 6c4009
#ifndef UINT_LEAST16_WIDTH
Packit 6c4009
# error "missing UINT_LEAST16_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX, UINT_LEAST16_WIDTH);
Packit 6c4009
#ifndef UINT_LEAST32_WIDTH
Packit 6c4009
# error "missing UINT_LEAST32_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX, UINT_LEAST32_WIDTH);
Packit 6c4009
#ifndef UINT_LEAST64_WIDTH
Packit 6c4009
# error "missing UINT_LEAST64_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX, UINT_LEAST64_WIDTH);
Packit 6c4009
Packit 6c4009
#ifndef INT_FAST8_WIDTH
Packit 6c4009
# error "missing INT_FAST8_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX, INT_FAST8_WIDTH);
Packit 6c4009
#ifndef INT_FAST16_WIDTH
Packit 6c4009
# error "missing INT_FAST16_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX, INT_FAST16_WIDTH);
Packit 6c4009
#ifndef INT_FAST32_WIDTH
Packit 6c4009
# error "missing INT_FAST32_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX, INT_FAST32_WIDTH);
Packit 6c4009
#ifndef INT_FAST64_WIDTH
Packit 6c4009
# error "missing INT_FAST64_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX, INT_FAST64_WIDTH);
Packit 6c4009
#ifndef UINT_FAST8_WIDTH
Packit 6c4009
# error "missing UINT_FAST8_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX, UINT_FAST8_WIDTH);
Packit 6c4009
#ifndef UINT_FAST16_WIDTH
Packit 6c4009
# error "missing UINT_FAST16_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX, UINT_FAST16_WIDTH);
Packit 6c4009
#ifndef UINT_FAST32_WIDTH
Packit 6c4009
# error "missing UINT_FAST32_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX, UINT_FAST32_WIDTH);
Packit 6c4009
#ifndef UINT_FAST64_WIDTH
Packit 6c4009
# error "missing UINT_FAST64_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX, UINT_FAST64_WIDTH);
Packit 6c4009
Packit 6c4009
#ifndef INTPTR_WIDTH
Packit 6c4009
# error "missing INTPTR_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (intptr_t, INTPTR_MAX, INTPTR_WIDTH);
Packit 6c4009
#ifndef UINTPTR_WIDTH
Packit 6c4009
# error "missing UINTPTR_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uintptr_t, UINTPTR_MAX, UINTPTR_WIDTH);
Packit 6c4009
Packit 6c4009
#ifndef INTMAX_WIDTH
Packit 6c4009
# error "missing INTMAX_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (intmax_t, INTMAX_MAX, INTMAX_WIDTH);
Packit 6c4009
#ifndef UINTMAX_WIDTH
Packit 6c4009
# error "missing UINTMAX_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (uintmax_t, UINTMAX_MAX, UINTMAX_WIDTH);
Packit 6c4009
Packit 6c4009
#ifndef PTRDIFF_WIDTH
Packit 6c4009
# error "missing PTRDIFF_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX, PTRDIFF_WIDTH);
Packit 6c4009
#ifndef SIG_ATOMIC_WIDTH
Packit 6c4009
# error "missing SIG_ATOMIC_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX, SIG_ATOMIC_WIDTH);
Packit 6c4009
#ifndef SIZE_WIDTH
Packit 6c4009
# error "missing SIZE_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (size_t, SIZE_MAX, SIZE_WIDTH);
Packit 6c4009
#ifndef WCHAR_WIDTH
Packit 6c4009
# error "missing WCHAR_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (wchar_t, WCHAR_MAX, WCHAR_WIDTH);
Packit 6c4009
#ifndef WINT_WIDTH
Packit 6c4009
# error "missing WINT_WIDTH"
Packit 6c4009
#endif
Packit 6c4009
  CHECK_WIDTH (wint_t, WINT_MAX, WINT_WIDTH);
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"