1 # Check for the presence of C99 features. Generally the check will fail
2 # if the feature isn't present (a C99 compiler isn't that much to ask,
5 # Check C99-style variadic macros (required):
7 # #define PRINTF(msg, ...) (printf(msg, __VA_ARGS__)
9 AC_DEFUN([FC_C99_VARIADIC_MACROS],
11 dnl Check for variadic macros
12 AC_CACHE_CHECK([for C99 variadic macros],
13 [ac_cv_c99_variadic_macros],
14 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
15 #define MSG(...) fprintf(stderr, __VA_ARGS__)
18 MSG("%s%d", "foo", 1);]])],[ac_cv_c99_variadic_macros=yes],[ac_cv_c99_variadic_macros=no])])
19 if test "x${ac_cv_c99_variadic_macros}" != "xyes"; then
20 AC_MSG_ERROR([A compiler supporting C99 variadic macros is required])
24 # Check C99-style initializers (required):
27 # struct timeval tv = {.tv_sec = 0, .tv_usec = 500000};
28 # int fibonacci[6] = {[0] = 0, [1] = 1, [2] = 1, [3] = 2, [4] = 3, [5] = 5};
29 # Note we do not check for multi-field initializers like
30 # struct { struct { int b; } a; } = {.a.b = 5}
31 # which are not supported by many compilers. It is best to avoid this
32 # problem by writing these using nesting. The above case becomes
33 # struct { struct { int b; } a; } = {.a = {.b = 5}}
34 AC_DEFUN([FC_C99_INITIALIZERS],
36 dnl Check for C99 initializers
37 AC_CACHE_CHECK([for C99 initializers],
38 [ac_cv_c99_initializers],
39 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[struct foo {
43 union {int x, y;} a_union;
45 ]], [[struct foo bar = {.an_array = {0, [3] = 2, [2] = 1, [4] = 3},
47 .a_string = "does it work?",
48 .a_union = {.y = 243}};]])],[ac_cv_c99_initializers=yes],[ac_cv_c99_initializers=no])])
49 if test "${ac_cv_c99_initializers}" != "yes"; then
50 AC_MSG_ERROR([A compiler supporting C99 initializers is required])
54 # Check C99-style stdint.h (required)
55 AC_DEFUN([FC_C99_STDINT_H],
57 AC_CHECK_HEADERS([stdint.h])
58 dnl Check for C99 stdint.h
59 AC_CACHE_CHECK([for C99 stdint.h],
61 [ac_cv_c99_stdint_h=$ac_cv_header_stdint_h])
62 if test "${ac_cv_c99_stdint_h}" != "yes"; then
63 AC_MSG_ERROR([A compiler supporting C99's stdint.h is required])
67 # Check that token concenation works as we expect
69 AC_DEFUN([FC_C99_TOKEN_CONCENATION],
71 AC_CACHE_CHECK([whether preprocessor token concenation works],
72 [ac_cv_c99_token_concenation],
73 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#define COMBINE(a, b) a ## b
74 #define CALLER(...) COMBINE(, __VA_ARGS__)]],
76 char *text = CALLER("string");]])],
77 [ac_cv_c99_token_concenation=yes],[ac_cv_c99_token_concenation=no])])
78 if test "x${ac_cv_c99_token_concenation}" != "xyes" ; then
79 AC_MSG_ERROR([A preprocessor supporting token concenation is required])
83 # Whether C99-style initializers of a struct can, or even must, be
85 # Sets macros INIT_BRACE_BEGIN and INIT_BRACE_END accordingly.
87 AC_DEFUN([FC_C99_INITIALIZER_BRACES],
89 AC_CACHE_CHECK([can struct initializers be within braces],
90 [ac_cv_c99_initializer_braces],
91 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
108 struct outer init_me = { 1, 2, { .inner = { 3, 4 }}}
110 [ac_cv_c99_initializer_braces=yes], [ac_cv_c99_initializer_braces=no])])
111 if test "x${ac_cv_c99_initializer_braces}" = "xyes" ; then
112 AC_DEFINE([INIT_BRACE_BEGIN], [{], [Beginning of C99 structure initializer])
113 AC_DEFINE([INIT_BRACE_END], [}], [End of C99 structure initializer])
115 AC_DEFINE([INIT_BRACE_BEGIN], [], [Beginning of C99 structure initializer])
116 AC_DEFINE([INIT_BRACE_END], [], [End of C99 structure initializer])