webperimental: killstack decides stack protects.
[freeciv.git] / m4 / c99.m4
blob158ac730bbb9e54fb2941ea35c615d88498a55bf
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,
3 # right?).
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__)
16           ]], [[MSG("foo");
17            MSG("%s", "foo");
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])
21   fi
24 # Check C99-style initializers (required):
26 # Examples:
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 {
40            int an_integer;
41            char *a_string;
42            int an_array[5];
43            union {int x, y;} a_union;
44          };
45         ]], [[struct foo bar = {.an_array = {0, [3] = 2, [2] = 1, [4] = 3},
46                            .an_integer = 999,
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])
51   fi
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],
60     [ac_cv_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])
64   fi
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__)]],
75     [[CALLER();
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])
80   fi
83 # Whether C99-style initializers of a struct can, or even must, be
84 # within braces.
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([],
92     [[
93 struct outer
95   int v1;
96   int v2;
97   union
98   {
99     int v3;
100     struct
101     {
102       int v4;
103       int v5;
104     } inner;
105   };
108   struct outer init_me = { 1, 2, { .inner = { 3, 4 }}}
109 ]])],
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])
114   else
115     AC_DEFINE([INIT_BRACE_BEGIN], [], [Beginning of C99 structure initializer])
116     AC_DEFINE([INIT_BRACE_END], [], [End of C99 structure initializer])
117   fi