AC_PROG_CC_C89 is not adding -std=c89 to CFLAGS

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

AC_PROG_CC_C89 is not adding -std=c89 to CFLAGS

Dimitrios Apostolou
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



_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: AC_PROG_CC_C89 is not adding -std=c89 to CFLAGS

Paul Eggert
Dimitrios Apostolou wrote:
> 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.

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: AC_PROG_CC_C89 is not adding -std=c89 to CFLAGS

Dimitrios Apostolou
On Fri, 13 Jan 2017, Paul Eggert wrote:

> Dimitrios Apostolou wrote:
>> 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.

>
> 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


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: AC_PROG_CC_C89 is not adding -std=c89 to CFLAGS

Zack Weinberg-2
In reply to this post by Dimitrios Apostolou
On Fri, Jan 13, 2017 at 8:12 PM, Dimitrios Apostolou <[hidden email]> wrote:
>
> 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.

> /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"

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

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf