autoconf
[Top][All Lists]
Advanced

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

Re: Selecting a C++ standard


From: Nick Bowler
Subject: Re: Selecting a C++ standard
Date: Tue, 30 Oct 2012 11:43:59 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

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.

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,
-- 
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)



reply via email to

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