Blame gnulib-tests/test-stddef.c

Packit Service fdd496
/* Test of <stddef.h> substitute.
Packit Service fdd496
   Copyright (C) 2009-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by Eric Blake <ebb9@byu.net>, 2009.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
#include <stddef.h>
Packit Service fdd496
#include <limits.h>
Packit Service fdd496
#include <stdalign.h>
Packit Service fdd496
#include "verify.h"
Packit Service fdd496
Packit Service fdd496
/* Check that appropriate types are defined.  */
Packit Service fdd496
wchar_t a = 'c';
Packit Service fdd496
ptrdiff_t b = 1;
Packit Service fdd496
size_t c = 2;
Packit Service fdd496
max_align_t x;
Packit Service fdd496
Packit Service fdd496
/* Check that NULL can be passed through varargs as a pointer type,
Packit Service fdd496
   per POSIX 2008.  */
Packit Service fdd496
verify (sizeof NULL == sizeof (void *));
Packit Service fdd496
Packit Service fdd496
/* Check that offsetof produces integer constants with correct type.  */
Packit Service fdd496
struct d
Packit Service fdd496
{
Packit Service fdd496
  char e;
Packit Service fdd496
  char f;
Packit Service fdd496
};
Packit Service fdd496
/* Solaris 10 has a bug where offsetof is under-parenthesized, and
Packit Service fdd496
   cannot be used as an arbitrary expression.  However, since it is
Packit Service fdd496
   unlikely to bite real code, we ignore that short-coming.  */
Packit Service fdd496
/* verify (sizeof offsetof (struct d, e) == sizeof (size_t)); */
Packit Service fdd496
verify (sizeof (offsetof (struct d, e)) == sizeof (size_t));
Packit Service fdd496
verify (offsetof (struct d, f) == 1);
Packit Service fdd496
Packit Service fdd496
/* offsetof promotes to an unsigned integer if and only if sizes do
Packit Service fdd496
   not fit in int.  */
Packit Service fdd496
verify ((offsetof (struct d, e) < -1) == (INT_MAX < (size_t) -1));
Packit Service fdd496
Packit Service fdd496
/* Check max_align_t's alignment.  */
Packit Service fdd496
verify (alignof (double) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (int) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (long double) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (long int) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (ptrdiff_t) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (size_t) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (wchar_t) <= alignof (max_align_t));
Packit Service fdd496
verify (alignof (struct d) <= alignof (max_align_t));
Packit Service fdd496
#if defined __GNUC__ || defined __IBM__ALIGNOF__
Packit Service fdd496
verify (__alignof__ (double) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (int) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (long double) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (long int) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (ptrdiff_t) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (size_t) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (wchar_t) <= __alignof__ (max_align_t));
Packit Service fdd496
verify (__alignof__ (struct d) <= __alignof__ (max_align_t));
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
main (void)
Packit Service fdd496
{
Packit Service fdd496
  return 0;
Packit Service fdd496
}