From: Harlan Stenn Date: Sat, 21 Feb 2015 07:15:54 +0000 (+0000) Subject: [Bug 2728] See if C99-style structure initialization works X-Git-Tag: NTP_4_2_8P2_RC1~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bb40d802e778861207ead347c0888becfa579db;p=thirdparty%2Fntp.git [Bug 2728] See if C99-style structure initialization works bk: 54e830aaj33zQmQnsCHG4Ktuk3Z2Ow --- diff --git a/ChangeLog b/ChangeLog index 400cf7934..969166443 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ --- + +* [Bug 2728] See if C99-style structure initialization works. +--- (4.2.8p1) 2015/02/04 Released by Harlan Stenn * Update the NEWS file. diff --git a/configure.ac b/configure.ac index 6942ceb53..d82ad2ed2 100644 --- a/configure.ac +++ b/configure.ac @@ -68,6 +68,7 @@ AC_PROG_CPP AC_PROG_CXX AC_PROG_YACC AC_PROG_CC_C_O +AX_C99_STRUCT_INIT NTP_VPATH_HACK dnl used only by ntpd/Makefile.am diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 56bc22802..8bd4fdbbc 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -330,7 +330,7 @@ typedef struct var_display_collection_tag { l_fp lfp; /* NTP_LFP */ } v; /* retrieved value */ } vdc; -#if !defined(MISSING_C99_STYLE_INIT) +#if !defined(MISSING_C99_STRUCT_INIT) # define VDC_INIT(a, b, c) { .tag = a, .display = b, .type = c } #else # define VDC_INIT(a, b, c) { a, b, c } diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index 6de8857c1..f56df9d0b 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -457,7 +457,7 @@ typedef unsigned long uintptr_t; #if defined(_MSC_VER) && _MSC_VER<1800 # define MISSING_INTTYPES_H 1 /* not provided by VS2012 and earlier */ # define MISSING_STDBOOL_H 1 /* not provided by VS2012 and earlier */ -# define MISSING_C99_STYLE_INIT 1 /* see [Bug 2728] */ +# define MISSING_C99_STRUCT_INIT 1 /* see [Bug 2728] */ #else #if defined(_MSC_VER) && _MSC_VER>=1800 /* VS2013 and above support C99 types */ diff --git a/sntp/m4/ax_c99_struct_init.m4 b/sntp/m4/ax_c99_struct_init.m4 new file mode 100644 index 000000000..44a2db3cf --- /dev/null +++ b/sntp/m4/ax_c99_struct_init.m4 @@ -0,0 +1,59 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_c99_struct_init.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_C99_STRUCT_INIT +# +# DESCRIPTION +# +# This macro defines MISSING_C99_STRUCT_INIT if the C compiler does not +# supports the C99 tagged structure initialization. +# +# Given: struct foo_s {int i1; int i2; int i3;}; +# one can write: +# #if !define(MISSING_C99_STRUCT_INIT) +# # define FOO_INIT(a, b, c) { .i1 = a, .i2 = b, .i3 = c } +# #else +# # define FOO_INIT(a, b, c) { a, b, c } +# +# static struct foo_s foo[] = { +# FOO_INIT(1, 1, 1), +# FOO_INIT(2, 2, 2), +# FOO_INIT(0, 0, 0) +# }; +# +# LICENSE +# +# Copyright (c) 2015 Network Time Foundation +# +# Author: Harlan Stenn +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([AX_C99_STRUCT_INIT], [ + AC_MSG_CHECKING([whether the compiler supports C99 structure initialization]) + AC_REQUIRE([AC_PROG_CC_C99]) + + AC_LANG_PUSH([C]) + + dnl AC_LINK_IFELSE? + AC_COMPILE_IFELSE( + [AC_LANG_SOURCE([[ + struct foo_s {int i1; int i2;}; + int main() { struct foo_s foo[] = { { .i1 = 1, .i2 = 1 }, { .i1 = 2, .i2 = 2 }, { .i1 = 0, .i2 = 0 } }; } + ]])], + AC_MSG_RESULT([yes]), + AC_MSG_RESULT([no]) + AC_DEFINE([MISSING_C99_STRUCT_INIT], [1], + [Define to 1 if the compiler does not support C99's structure initialization.]), + ) + + AC_LANG_POP([C]) + ]);