[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C99 support
From: |
Roger Leigh |
Subject: |
Re: C99 support |
Date: |
Mon, 29 Nov 2004 18:26:12 +0000 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
"Kevin P. Fleming" <address@hidden> writes:
> Roger Leigh wrote:
>
>> and these work well. What it doesn't do is let me use features such
>> as mixed declarations and code. These require you to use "gcc
>> -std=c99" or "c99" or similar, and I can't enable this portably. If
>> autoconf could find out how to put a given compiler into C99 mode,
>> that would be great (in the same way as AC_PROG_GCC_TRADITIONAL
>> works for K&R C).
>
> This sort of test is also needed to test C99 support for anonymous
> unions and structures in declarators, which I have run into problems
> with before.
>
> If there's a way to create AC_PROG_CC_C99 or something similar, that
> would be wonderful.
Here we go (based on _AC_PROG_CC_STDC). This currently only works
with GCC; it's trivial to support others. The code is pretty
brain-dead, so I'm sure there are more interesting ways of testing
C99 support (possibly including the current ANSI C tests as well).
# AC_PROG_CC_C99
# ----------------
# If the C compiler in not in ISO C99 C mode by default, try to add an
# option to output variable @code{CC} to make it so. This macro tries
# various options that select ISO C99 C on some system or another. It
# considers the compiler to be in ISO C99 C mode if it handles mixed
# code and declarations, _Bool, inline and restrict.
AC_DEFUN([AC_PROG_CC_C99],
[AC_MSG_CHECKING([for $CC option to accept ISO C99 C])
AC_CACHE_VAL(ac_cv_prog_cc_c99,
[ac_cv_prog_cc_c99=no
ac_save_CC=$CC
AC_LANG_CONFTEST([AC_LANG_PROGRAM(
[[static inline int
test(const char *restrict text)
{
int i = 0;
while (*(text+i) != '\0')
++i;
return 0;
}]],
[[_Bool success = 1;
if (test("String literal") != 0)
success = 0;
char *restrict newvar = "Another string";]])])
# Try
# GCC -std=c99 -std=iso9899:1999
for ac_arg in "" -std=c99 -std=iso9899:1999
do
CC="$ac_save_CC $ac_arg"
_AC_COMPILE_IFELSE([],
[ac_cv_prog_cc_c99=$ac_arg
break])
done
rm -f conftest.$ac_ext conftest.$ac_objext
CC=$ac_save_CC
])
case "x$ac_cv_prog_cc_c99" in
x|xno)
AC_MSG_RESULT([none needed]) ;;
*)
AC_MSG_RESULT([$ac_cv_prog_cc_c99])
CC="$CC $ac_cv_prog_cc_c99" ;;
esac
])# _AC_PROG_CC_C99
And this is a little patch for c.m4:
- --- /usr/share/autoconf/autoconf/c.m4 2004-11-23 23:19:42.000000000 +0000
+++ c99.m4 2004-11-29 18:19:33.000000000 +0000
@@ -461,6 +461,9 @@
AC_CHECK_TOOL(CC, cc)
fi
if test -z "$CC"; then
+ AC_CHECK_PROGS(CC, [c99 c89])
+fi
+if test -z "$CC"; then
AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
fi
if test -z "$CC"; then
It would be great if in the next year, AC_PROG_CC could default to
using a C99 compiler. Since it should be backward-compatible with C89
(??), this shouldn't be required, but I would really like to see C99
as the default, with some means of choosing an older standard if so
required.
Regards,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQFBq2m1VcFcaSW/uEgRAs6sAKDYDAqCORidgrHCJVz6pjo5Cu6ktQCeKAh6
9rRaZXOzwgI++jw3WfAGF38=
=bStj
-----END PGP SIGNATURE-----
- C99 support, Roger Leigh, 2004/11/28
- Re: C99 support, Andreas Schwab, 2004/11/28
- Re: C99 support, Roger Leigh, 2004/11/28
- Re: C99 support, Kevin P. Fleming, 2004/11/28
- Re: C99 support, Gary V. Vaughan, 2004/11/28
- Re: C99 support,
Roger Leigh <=
- Re: C99 support, Bob Friesenhahn, 2004/11/29
- Re: C99 support, Roger Leigh, 2004/11/29
- Re: C99 support, Bob Friesenhahn, 2004/11/29
- Re: C99 support, Roger Leigh, 2004/11/29
- Re: C99 support, Bob Friesenhahn, 2004/11/29
- Re: C99 support, Austin Schutz, 2004/11/29
- Re: C99 support, Ralf Wildenhues, 2004/11/30
- Re: C99 support, Paul Eggert, 2004/11/30
- Re: C99 support, Ralf Wildenhues, 2004/11/30
- Re: C99 support, Ralf Wildenhues, 2004/11/30