1# ===========================================================================
2#       http://www.gnu.org/software/autoconf-archive/ax_c99_struct_init.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_C99_STRUCT_INIT
8#
9# DESCRIPTION
10#
11#   This macro defines MISSING_C99_STRUCT_INIT if the C compiler does not
12#   supports the C99 tagged structure initialization.
13#
14#   Given: struct foo_s {int i1; int i2; int i3;};
15#   one can write:
16#         #if !define(MISSING_C99_STRUCT_INIT)
17#         # define FOO_INIT(a, b, c) { .i1 = a, .i2 = b, .i3 = c }
18#         #else
19#         # define FOO_INIT(a, b, c) { a, b, c }
20#
21#         static struct foo_s foo[] = {
22#                   FOO_INIT(1, 1, 1),
23#                   FOO_INIT(2, 2, 2),
24#                   FOO_INIT(0, 0, 0)
25#         };
26#
27# LICENSE
28#
29#   Copyright (c) 2015 Network Time Foundation
30#
31#   Author: Harlan Stenn <stenn@nwtime.org>
32#
33#   Copying and distribution of this file, with or without modification, are
34#   permitted in any medium without royalty provided the copyright notice
35#   and this notice are preserved. This file is offered as-is, without any
36#   warranty.
37
38#serial 1
39
40AC_DEFUN([AX_C99_STRUCT_INIT], [
41          AC_MSG_CHECKING([whether the compiler supports C99 structure initialization])
42          AC_REQUIRE([AC_PROG_CC_C99])
43
44          AC_LANG_PUSH([C])
45
46          dnl AC_LINK_IFELSE?
47          AC_COMPILE_IFELSE(
48                    [AC_LANG_SOURCE([[
49                              struct foo_s {int i1; int i2;};
50                              int main() { struct foo_s foo[] = { { .i1 = 1, .i2 = 1 }, { .i1 = 2, .i2 = 2 }, { .i1 = 0, .i2 = 0 } }; }
51                              ]])],
52                    AC_MSG_RESULT([yes]),
53                    AC_MSG_RESULT([no])
54                    AC_DEFINE([MISSING_C99_STRUCT_INIT], [1],
55                              [Define to 1 if the compiler does not support C99's structure initialization.]),
56                    )
57
58          AC_LANG_POP([C])
59          ]);
60