1 # stddef_h.m4 serial 12
2 dnl Copyright (C) 2009-2022 Free Software Foundation, Inc.
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.
7 dnl A placeholder for <stddef.h>, for platforms that have issues.
9 AC_DEFUN_ONCE([gl_STDDEF_H],
11 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
12 AC_REQUIRE([gt_TYPE_WCHAR_T])
14 dnl Persuade OpenBSD <stddef.h> to declare max_align_t.
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 GL_GENERATE_STDDEF_H=false
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],
26 unsigned int s = sizeof (max_align_t);
27 #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
28 int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
29 int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
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];
39 [gl_cv_type_max_align_t=yes],
40 [gl_cv_type_max_align_t=no])
42 if test $gl_cv_type_max_align_t = no; then
44 GL_GENERATE_STDDEF_H=true
47 if test $gt_cv_c_wchar_t = no; then
49 GL_GENERATE_STDDEF_H=true
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];
57 [gl_cv_decl_null_works=yes],
58 [gl_cv_decl_null_works=no])])
59 if test $gl_cv_decl_null_works = no; then
61 GL_GENERATE_STDDEF_H=true
64 if $GL_GENERATE_STDDEF_H; then
65 gl_NEXT_HEADERS([stddef.h])
69 # gl_STDDEF_MODULE_INDICATOR([modulename])
70 # sets the shell variable that indicates the presence of the given module
71 # to a C preprocessor expression that will evaluate to 1.
72 # This macro invocation must not occur in macros that are AC_REQUIREd.
73 AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
75 dnl Ensure to expand the default settings once only.
76 gl_STDDEF_H_REQUIRE_DEFAULTS
77 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
80 # Initializes the default values for AC_SUBSTed shell variables.
81 # This macro must not be AC_REQUIREd. It must only be invoked, and only
82 # outside of macros or in macros that are not AC_REQUIREd.
83 AC_DEFUN([gl_STDDEF_H_REQUIRE_DEFAULTS],
85 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS], [
87 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS])
88 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
91 AC_DEFUN([gl_STDDEF_H_DEFAULTS],
93 dnl Assume proper GNU behavior unless another module says otherwise.
94 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
95 HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T])
96 HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T])