Re: C23 support in Autoconf

2024-05-01 Thread Nick Bowler
On 2024-04-30 21:59, Jacob Bachmeyer wrote:
> Paul Eggert wrote:
>> While we're adding to our wishlist that should also be a
>> configure-time option, not merely something in configure.ac. That
>> way, one could test a tarball's portability without having to modify
>> the source code.

This is already possible.  Just configure with CFLAGS=-std=c99 or
whatever.

> Perhaps --with-C-language-standard={C89,C99,C11,C23} and a
> --with-strict-C-language to select (example) c99 instead of gnu99?

In my opinion we should not add options like this to every package.
Unless I'm missing something, outside of some rare edge cases, a user
actually using such an option is going to achieve nothing at best and
otherwise change a package from "working" into "not working."  It is
not helpful to users to present them with useless options.

The realistic edge cases (such as the many historical GNU packages which
were broken by GCC's change of defaults to gnu11) can already be handled
by CFLAGS.

Cheers,
  Nick



Re: C23 support in Autoconf

2024-05-01 Thread Paul Eggert

On 2024-05-01 05:33, Nick Bowler wrote:

Just configure with CFLAGS=-std=c99 or whatever.


I was thinking along the same line. We should keep things simple. Using 
CFLAGS is a documented way to specify the compiler flags, and ideally 
there would be no need for a new feature in this area.


However, I have some qualms. './configure CFLAGS=-std=c99' works 
somewhat by accident, because it tries things in the following order:


 echo ' ... C23 test ... ' >conftest.c
 gcc -std=c99 conftest.c
 gcc -std=gnu23 -std=c99  conftest.c
 echo ' ... C11 test ... ' >conftest.c
 gcc -std=c99 conftest.c
 gcc -std=gnu11 -std=c99  conftest.c
 gcc -std:c11 -std=c99 conftest.c
 echo ' ... C99 test ... ' >conftest.c
 gcc -std=c99 conftest.c

The last GCC invocation is the first one that works, so 'configure' 
announces that it has enabled C99 features.


This approach works because GCC treats a later -std= option as 
overriding an earlier one. Does the same thing happen with other compilers?


If not, there should be a way for the builder to say "Don't try to mess 
with the C standard version; just leave $CC alone". With current 
Autoconf on Savannah there's a hacky way to do that:


  ./configure CC='-std=c99' ac_cv_prog_cc_c23=

but that sort of thing is not something we want to document, as it 
depends on the Autoconf version. So perhaps there should be a better way 
to disable the C standard version testing that AC_PROG_CC normally does.