VirtualBox

source: kBuild/vendor/grep/3.7/gnulib-tests/test-stddef.c@ 3529

Last change on this file since 3529 was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette