Discussion:
AC_PROG_CC_C89 is not adding -std=c89 to CFLAGS
Dimitrios Apostolou
2017-01-14 01:12:52 UTC
Permalink
Hello list,

recent GCC versions default to C99 or even C11. I was expecting that
adding AC_PROG_CC_C89 to configure.ac, would force C89, probably by using
-std=gnu89. But this was not the case. Any ideas why?


Context is compiling a C program using a recent gcc on Solaris 10,
resulted to this error:

/opt/csw/lib/gcc/i386-pc-solaris2.10/5.2.0/include-fixed/sys/feature_tests.h:346:2:
error: #error "Compiler or options invalid for pre-UNIX 03 X/Open
applications and pre-2001 POSIX applications"


From the header file:

#if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
and pre-2001 POSIX applications"
#elif !defined(_STDC_C99) && \
(defined(__XOPEN_OR_POSIX) && defined(_XPG6))
#error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications
\
require the use of c99"
#endif


Thank you in advance,
Dimitris
Paul Eggert
2017-01-14 03:13:51 UTC
Permalink
I was expecting that adding AC_PROG_CC_C89 to configure.ac, would force C89
Eeeuuw. Who would want to do that?

To some extent AC_PROG_CC_C89 is obsolete, and I don't recommend using it, just
as I don't recommend C89.
Dimitrios Apostolou
2017-01-16 14:16:52 UTC
Permalink
Post by Paul Eggert
I was expecting that adding AC_PROG_CC_C89 to configure.ac, would force C89
Eeeuuw. Who would want to do that?
See the context in my first email, apparently some defines were not very
well thought. Passing -std=gnu89 to CFLAGS helped me move on.
Post by Paul Eggert
To some extent AC_PROG_CC_C89 is obsolete, and I don't recommend using it,
just as I don't recommend C89.
I fully agree, for code I own. :-)


Dimitris
Zack Weinberg
2017-01-16 14:47:40 UTC
Permalink
recent GCC versions default to C99 or even C11. I was expecting that adding
AC_PROG_CC_C89 to configure.ac, would force C89, probably by using
-std=gnu89. But this was not the case. Any ideas why?
Originally, AC_PROG_CC_C89 meant "make sure the C compiler supports
_at least_ C89". It was for programs that couldn't be compiled with a
K&R compiler. (Remember that Autoconf has been around since the
1990s.)

Nowadays, your use case is probably more common, but it's still rare
enough that I doubt it makes sense for Autoconf to have a built-in
feature for it. And I don't think we can safely change what
AC_PROG_CC_C89 does. I would suggest manually splicing `-std=gnu89`
into the CC variable (not CFLAGS) after AC_PROG_CC, conditional on
$GCC.
error: #error "Compiler or options invalid for pre-UNIX 03 X/Open
applications and pre-2001 POSIX applications"
Solaris is tedious like that, yes. But did you really _want_ an old
POSIX conformance level? I can see wanting POSIX.1-2001 specifically,
since -2008 removed a number of useful things (gettimeofday,
swapcontext, etc) but pre-2001 seems unlikely. You might try
AC_USE_SYSTEM_EXTENSIONS.

zw

Loading...