Commit | Line | Data |
---|---|---|
9c9d63b1 PM |
1 | # stddef_h.m4 serial 9 |
2 | dnl Copyright (C) 2009-2021 Free Software Foundation, Inc. | |
f434ba03 PA |
3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | |
5 | dnl with or without modifications, as long as this notice is preserved. | |
6 | ||
9c9d63b1 PM |
7 | dnl A placeholder for <stddef.h>, for platforms that have issues. |
8 | ||
f434ba03 PA |
9 | AC_DEFUN([gl_STDDEF_H], |
10 | [ | |
11 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) | |
12 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | |
9c9d63b1 PM |
13 | |
14 | dnl Persuade OpenBSD <stddef.h> to declare max_align_t. | |
15 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | |
16 | ||
770d76d7 | 17 | STDDEF_H= |
c0c3707f CB |
18 | |
19 | dnl Test whether the type max_align_t exists and whether its alignment | |
20 | dnl "is as great as is supported by the implementation in all contexts". | |
21 | AC_CACHE_CHECK([for good max_align_t], | |
22 | [gl_cv_type_max_align_t], | |
23 | [AC_COMPILE_IFELSE( | |
24 | [AC_LANG_PROGRAM( | |
25 | [[#include <stddef.h> | |
26 | unsigned int s = sizeof (max_align_t); | |
9c9d63b1 | 27 | #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__ |
c0c3707f CB |
28 | int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1]; |
29 | int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1]; | |
30 | #endif | |
9c9d63b1 PM |
31 | typedef struct { char a; max_align_t b; } max_helper; |
32 | typedef struct { char a; long b; } long_helper; | |
33 | typedef struct { char a; double b; } double_helper; | |
34 | typedef struct { char a; long double b; } long_double_helper; | |
35 | int check3[2 * (offsetof (long_helper, b) <= offsetof (max_helper, b)) - 1]; | |
36 | int check4[2 * (offsetof (double_helper, b) <= offsetof (max_helper, b)) - 1]; | |
37 | int check5[2 * (offsetof (long_double_helper, b) <= offsetof (max_helper, b)) - 1]; | |
c0c3707f CB |
38 | ]])], |
39 | [gl_cv_type_max_align_t=yes], | |
40 | [gl_cv_type_max_align_t=no]) | |
41 | ]) | |
42 | if test $gl_cv_type_max_align_t = no; then | |
43 | HAVE_MAX_ALIGN_T=0 | |
44 | STDDEF_H=stddef.h | |
45 | fi | |
46 | ||
f434ba03 PA |
47 | if test $gt_cv_c_wchar_t = no; then |
48 | HAVE_WCHAR_T=0 | |
49 | STDDEF_H=stddef.h | |
50 | fi | |
c0c3707f | 51 | |
f434ba03 PA |
52 | AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], |
53 | [gl_cv_decl_null_works], | |
54 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h> | |
55 | int test[2 * (sizeof NULL == sizeof (void *)) -1]; | |
56 | ]])], | |
57 | [gl_cv_decl_null_works=yes], | |
58 | [gl_cv_decl_null_works=no])]) | |
59 | if test $gl_cv_decl_null_works = no; then | |
60 | REPLACE_NULL=1 | |
61 | STDDEF_H=stddef.h | |
62 | fi | |
c0c3707f | 63 | |
770d76d7 PA |
64 | AC_SUBST([STDDEF_H]) |
65 | AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) | |
f434ba03 | 66 | if test -n "$STDDEF_H"; then |
770d76d7 | 67 | gl_NEXT_HEADERS([stddef.h]) |
f434ba03 PA |
68 | fi |
69 | ]) | |
70 | ||
71 | AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], | |
72 | [ | |
73 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | |
74 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) | |
75 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) | |
76 | ]) | |
77 | ||
78 | AC_DEFUN([gl_STDDEF_H_DEFAULTS], | |
79 | [ | |
80 | dnl Assume proper GNU behavior unless another module says otherwise. | |
81 | REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) | |
4a626d0a | 82 | HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T]) |
f434ba03 | 83 | HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) |
f434ba03 | 84 | ]) |