autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Selecting a C++ standard


From: Adrian Bunk
Subject: Re: Selecting a C++ standard
Date: Tue, 30 Oct 2012 18:11:58 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Oct 30, 2012 at 11:43:59AM -0400, Nick Bowler wrote:
> On 2012-10-30 16:35 +0200, Adrian Bunk wrote:
> > On Sun, Oct 28, 2012 at 11:46:51AM -0500, Bob Friesenhahn wrote:
> > >...
> > > If the code was written for C89 then I am likely to want to continue
> > > compiling it for C89 if possible but also allow "best effort" if the
> > > compiler does not have a C89 mode.  If the code is updated to also
> > > work properly for C99, then C99 can be requested.
> > > 
> > > Those of us who updated C89 code to work with C99 compilers realize
> > > that it is not necessarily a trivial task (e.g. changes to aliasing
> > > rules).  C99 code can be written in a way that it will work with C89
> > > compilers, but C89-originated code may malfunction when compiled
> > > with C99 compilers.
> > 
> > If that is be true, then we have a serious problem with the current 
> > autoconf master.
> > 
> > Can you provide an example C89 program that does malfunction with
> > a C99 compiler?
> 
> The semantic changes in C99 were mostly conservative, and probably don't
> break many "real" applications, but there are certainly some subtle
> semantic differences.  One of my favourite examples is a change to the
> block scoping which can be observed with a program such as the
> following, which is strictly conforming in both C89 and C99:
> 
>   #include <stdio.h>
> 
>   enum {A, B} has_c99_scoping_rules(void)
>   {
>     if ((enum {B, A})0)
>       ;
>     return B;
>   }
> 
>   int main(void)
>   {
>     if (has_c99_scoping_rules())
>       puts("Compiler uses C99 block scoping");
>     else
>       puts("Compiler uses C89 block scoping");
>     return 0;
>   }
> 
> GCC in its default mode (gnu89) uses C89 scoping rules.  Of course,
> this behaviour is clearly possible to write a specific test for, as
> I just did.


Thanks for this example, it shows that there is actually a risk 
associated with the change currently in autoconf git.

As of today, typical software using AC_PROG_CC will:
- be compiled in C89 mode with autoconf <= 2.69
- be compiled in C11 mode with autoconf >= 2.70

So if your example program would be built using autoconf, it would 
behave differently depending on the autoconf version used.


> I can't think offhand of a program which is well-defined in C89 that
> would violate the C99 aliasing restrictions (and therefore have
> undefined behaviour in C99).  Regardless, AFAIK GCC implements the
> same restrictions in C89 mode too, so switching to C89 mode wouldn't
> actually help in this case.
> 
> Cheers,

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed




reply via email to

[Prev in Thread] Current Thread [Next in Thread]