source: trunk/src/sed/gnulib-tests/test-stddef.c@ 3618

Last change on this file since 3618 was 3611, checked in by bird, 10 months ago

vendor/sed/current: GNU sed 4.9 (sed-4.9.tar.xz sha256:6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181)

File size: 2.9 KB
Line 
1/* Test of <stddef.h> substitute.
2 Copyright (C) 2009-2022 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 Eric Blake <ebb9@byu.net>, 2009. */
18
19#include <config.h>
20
21#include <stddef.h>
22#include <limits.h>
23#include <stdalign.h>
24
25/* Check that appropriate types are defined. */
26wchar_t a = 'c';
27ptrdiff_t b = 1;
28size_t c = 2;
29max_align_t x;
30
31/* Check that NULL can be passed through varargs as a pointer type,
32 per POSIX 2008. */
33static_assert (sizeof NULL == sizeof (void *));
34
35/* Check that offsetof produces integer constants with correct type. */
36struct d
37{
38 char e;
39 char f;
40};
41/* Solaris 10 has a bug where offsetof is under-parenthesized, and
42 cannot be used as an arbitrary expression. However, since it is
43 unlikely to bite real code, we ignore that short-coming. */
44/* static_assert (sizeof offsetof (struct d, e) == sizeof (size_t)); */
45static_assert (sizeof (offsetof (struct d, e)) == sizeof (size_t));
46static_assert (offsetof (struct d, f) == 1);
47
48/* offsetof promotes to an unsigned integer if and only if sizes do
49 not fit in int. */
50static_assert ((offsetof (struct d, e) < -1) == (INT_MAX < (size_t) -1));
51
52/* Check max_align_t's alignment. */
53static_assert (alignof (double) <= alignof (max_align_t));
54static_assert (alignof (int) <= alignof (max_align_t));
55static_assert (alignof (long double) <= alignof (max_align_t));
56static_assert (alignof (long int) <= alignof (max_align_t));
57static_assert (alignof (ptrdiff_t) <= alignof (max_align_t));
58static_assert (alignof (size_t) <= alignof (max_align_t));
59static_assert (alignof (wchar_t) <= alignof (max_align_t));
60static_assert (alignof (struct d) <= alignof (max_align_t));
61#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
62static_assert (__alignof__ (double) <= __alignof__ (max_align_t));
63static_assert (__alignof__ (int) <= __alignof__ (max_align_t));
64static_assert (__alignof__ (long double) <= __alignof__ (max_align_t));
65static_assert (__alignof__ (long int) <= __alignof__ (max_align_t));
66static_assert (__alignof__ (ptrdiff_t) <= __alignof__ (max_align_t));
67static_assert (__alignof__ (size_t) <= __alignof__ (max_align_t));
68static_assert (__alignof__ (wchar_t) <= __alignof__ (max_align_t));
69static_assert (__alignof__ (struct d) <= __alignof__ (max_align_t));
70#endif
71
72int
73main (void)
74{
75 return 0;
76}
Note: See TracBrowser for help on using the repository browser.