@@ -4425,6 +4425,183 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
44254425ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
44264426ac_compiler_gnu=$ac_cv_c_compiler_gnu
44274427
4428+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C99" >&5
4429+ $as_echo_n "checking for $CC option to accept ISO C99... " >&6; }
4430+ if ${ac_cv_prog_cc_c99+:} false; then :
4431+ $as_echo_n "(cached) " >&6
4432+ else
4433+ ac_cv_prog_cc_c99=no
4434+ ac_save_CC=$CC
4435+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4436+ /* end confdefs.h. */
4437+ #include <stdarg.h>
4438+ #include <stdbool.h>
4439+ #include <stdlib.h>
4440+ #include <wchar.h>
4441+ #include <stdio.h>
4442+
4443+ // Check varargs macros. These examples are taken from C99 6.10.3.5.
4444+ #define debug(...) fprintf (stderr, __VA_ARGS__)
4445+ #define showlist(...) puts (#__VA_ARGS__)
4446+ #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
4447+ static void
4448+ test_varargs_macros (void)
4449+ {
4450+ int x = 1234;
4451+ int y = 5678;
4452+ debug ("Flag");
4453+ debug ("X = %d\n", x);
4454+ showlist (The first, second, and third items.);
4455+ report (x>y, "x is %d but y is %d", x, y);
4456+ }
4457+
4458+ // Check long long types.
4459+ #define BIG64 18446744073709551615ull
4460+ #define BIG32 4294967295ul
4461+ #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
4462+ #if !BIG_OK
4463+ your preprocessor is broken;
4464+ #endif
4465+ #if BIG_OK
4466+ #else
4467+ your preprocessor is broken;
4468+ #endif
4469+ static long long int bignum = -9223372036854775807LL;
4470+ static unsigned long long int ubignum = BIG64;
4471+
4472+ struct incomplete_array
4473+ {
4474+ int datasize;
4475+ double data[];
4476+ };
4477+
4478+ struct named_init {
4479+ int number;
4480+ const wchar_t *name;
4481+ double average;
4482+ };
4483+
4484+ typedef const char *ccp;
4485+
4486+ static inline int
4487+ test_restrict (ccp restrict text)
4488+ {
4489+ // See if C++-style comments work.
4490+ // Iterate through items via the restricted pointer.
4491+ // Also check for declarations in for loops.
4492+ for (unsigned int i = 0; *(text+i) != '\0'; ++i)
4493+ continue;
4494+ return 0;
4495+ }
4496+
4497+ // Check varargs and va_copy.
4498+ static void
4499+ test_varargs (const char *format, ...)
4500+ {
4501+ va_list args;
4502+ va_start (args, format);
4503+ va_list args_copy;
4504+ va_copy (args_copy, args);
4505+
4506+ const char *str;
4507+ int number;
4508+ float fnumber;
4509+
4510+ while (*format)
4511+ {
4512+ switch (*format++)
4513+ {
4514+ case 's': // string
4515+ str = va_arg (args_copy, const char *);
4516+ break;
4517+ case 'd': // int
4518+ number = va_arg (args_copy, int);
4519+ break;
4520+ case 'f': // float
4521+ fnumber = va_arg (args_copy, double);
4522+ break;
4523+ default:
4524+ break;
4525+ }
4526+ }
4527+ va_end (args_copy);
4528+ va_end (args);
4529+ }
4530+
4531+ int
4532+ main ()
4533+ {
4534+
4535+ // Check bool.
4536+ _Bool success = false;
4537+
4538+ // Check restrict.
4539+ if (test_restrict ("String literal") == 0)
4540+ success = true;
4541+ char *restrict newvar = "Another string";
4542+
4543+ // Check varargs.
4544+ test_varargs ("s, d' f .", "string", 65, 34.234);
4545+ test_varargs_macros ();
4546+
4547+ // Check flexible array members.
4548+ struct incomplete_array *ia =
4549+ malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
4550+ ia->datasize = 10;
4551+ for (int i = 0; i < ia->datasize; ++i)
4552+ ia->data[i] = i * 1.234;
4553+
4554+ // Check named initializers.
4555+ struct named_init ni = {
4556+ .number = 34,
4557+ .name = L"Test wide string",
4558+ .average = 543.34343,
4559+ };
4560+
4561+ ni.number = 58;
4562+
4563+ int dynamic_array[ni.number];
4564+ dynamic_array[ni.number - 1] = 543;
4565+
4566+ // work around unused variable warnings
4567+ return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
4568+ || dynamic_array[ni.number - 1] != 543);
4569+
4570+ ;
4571+ return 0;
4572+ }
4573+ _ACEOF
4574+ for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc99
4575+ do
4576+ CC="$ac_save_CC $ac_arg"
4577+ if ac_fn_c_try_compile "$LINENO"; then :
4578+ ac_cv_prog_cc_c99=$ac_arg
4579+ fi
4580+ rm -f core conftest.err conftest.$ac_objext
4581+ test "x$ac_cv_prog_cc_c99" != "xno" && break
4582+ done
4583+ rm -f conftest.$ac_ext
4584+ CC=$ac_save_CC
4585+
4586+ fi
4587+ # AC_CACHE_VAL
4588+ case "x$ac_cv_prog_cc_c99" in
4589+ x)
4590+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
4591+ $as_echo "none needed" >&6; } ;;
4592+ xno)
4593+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
4594+ $as_echo "unsupported" >&6; } ;;
4595+ *)
4596+ CC="$CC $ac_cv_prog_cc_c99"
4597+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5
4598+ $as_echo "$ac_cv_prog_cc_c99" >&6; } ;;
4599+ esac
4600+ if test "x$ac_cv_prog_cc_c99" != xno; then :
4601+
4602+ fi
4603+
4604+
44284605ac_ext=cpp
44294606ac_cpp='$CXXCPP $CPPFLAGS'
44304607ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
0 commit comments