1281348Scy# =========================================================================== 2281348Scy# http://www.gnu.org/software/autoconf-archive/ax_c99_struct_init.html 3281348Scy# =========================================================================== 4281348Scy# 5281348Scy# SYNOPSIS 6281348Scy# 7281348Scy# AX_C99_STRUCT_INIT 8281348Scy# 9281348Scy# DESCRIPTION 10281348Scy# 11281348Scy# This macro defines MISSING_C99_STRUCT_INIT if the C compiler does not 12281348Scy# supports the C99 tagged structure initialization. 13281348Scy# 14281348Scy# Given: struct foo_s {int i1; int i2; int i3;}; 15281348Scy# one can write: 16281348Scy# #if !define(MISSING_C99_STRUCT_INIT) 17281348Scy# # define FOO_INIT(a, b, c) { .i1 = a, .i2 = b, .i3 = c } 18281348Scy# #else 19281348Scy# # define FOO_INIT(a, b, c) { a, b, c } 20281348Scy# 21281348Scy# static struct foo_s foo[] = { 22281348Scy# FOO_INIT(1, 1, 1), 23281348Scy# FOO_INIT(2, 2, 2), 24281348Scy# FOO_INIT(0, 0, 0) 25281348Scy# }; 26281348Scy# 27281348Scy# LICENSE 28281348Scy# 29281348Scy# Copyright (c) 2015 Network Time Foundation 30281348Scy# 31281348Scy# Author: Harlan Stenn <stenn@nwtime.org> 32281348Scy# 33281348Scy# Copying and distribution of this file, with or without modification, are 34281348Scy# permitted in any medium without royalty provided the copyright notice 35281348Scy# and this notice are preserved. This file is offered as-is, without any 36281348Scy# warranty. 37281348Scy 38281348Scy#serial 1 39281348Scy 40281348ScyAC_DEFUN([AX_C99_STRUCT_INIT], [ 41281348Scy AC_MSG_CHECKING([whether the compiler supports C99 structure initialization]) 42281348Scy AC_REQUIRE([AC_PROG_CC_C99]) 43281348Scy 44281348Scy AC_LANG_PUSH([C]) 45281348Scy 46281348Scy dnl AC_LINK_IFELSE? 47281348Scy AC_COMPILE_IFELSE( 48281348Scy [AC_LANG_SOURCE([[ 49281348Scy struct foo_s {int i1; int i2;}; 50281348Scy int main() { struct foo_s foo[] = { { .i1 = 1, .i2 = 1 }, { .i1 = 2, .i2 = 2 }, { .i1 = 0, .i2 = 0 } }; } 51281348Scy ]])], 52281348Scy AC_MSG_RESULT([yes]), 53281348Scy AC_MSG_RESULT([no]) 54281348Scy AC_DEFINE([MISSING_C99_STRUCT_INIT], [1], 55281348Scy [Define to 1 if the compiler does not support C99's structure initialization.]), 56281348Scy ) 57281348Scy 58281348Scy AC_LANG_POP([C]) 59281348Scy ]); 60