Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #152859

Re: Two different Results between C and C++

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Two different Results between C and C++
Date 2020-06-21 01:25 -0700
Organization A noiseless patient Spider
Message-ID <868sggkepa.fsf@linuxsc.com> (permalink)
References <rb5mq9$okv$1@gioia.aioe.org> <8c6495f9-6139-464e-ac8f-4eac27a92776@googlegroups.com> <rb5v6i$pv5$1@dont-email.me> <60d0f73c-8588-4673-a48d-e5c4cc726196@googlegroups.com> <rb6ajh$33k$1@dont-email.me>

Show all headers | View raw


James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 6/2/20 2:39 PM, John Bode wrote:
>
>> On Tuesday, June 2, 2020 at 11:36:43 AM UTC-5, James Kuyper wrote:
>>
>>> On 6/2/20 11:41 AM, John Bode wrote:
>
> ...
>
>>>> C and C++ are completely different languages, so this shouldn't
>>>> be surprising.
>>>
>>> C and C++ are two different but very similar languages.  The
>>> overwhelming majority of the features of C are also features of
>>> C++ (the reverse is not true - it doesn't even come close).
>>> Therefore, it is entirely reasonable to be surprised by two of the
>>> few exceptions to that rule.
>>>
>>> Annex C of the C++ standard details the differences between the
>>> two languages, excluding the differences that take the form of
>>> adding completely new features to C++.  It only takes 24 of the
>>> 1600+ pages of the C++ standard, which is an indication of how few
>>> those differences really are.  Keep in mind that much of the C
>>> standard (mostly the part describing the C standard library) is
>>> incorporated into the C++ standard by reference.  If those
>>> cross-references were replaced by the text they cross-reference,
>>> it would add nearly 300 pages to the document, so it should more
>>> accurately be described as 24 pages out of roughly 1900.
>>>
>>> C++ was originally intended to be a set of features that would be
>>> added to C, rather than a brand new language, and the initial
>>> design of C++ reflected that fact.  Even after Stroustrup realized
>>> that it would have to become a distinct language, backwards
>>> compatibility with C remained one of his key design goals.  When
>>> they started standardizing C++, the C++ committee worked out an
>>> agreement with the C committee to prohibit the invention of
>>> gratuitous new differences between the languages.  Differences are
>>> allowed, and have been created, but only if, in the opinion of the
>>> two committees, those differences are adequately motivated.
>>
>> The two languages have diverged *enough* at this point that it's
>> much less ass-bitey to approach them as being completely different.
>> Maybe not *as* different as, say, C and Java, but we're all better
>> served by viewing them that way.
>>
>> There are an infinite number of programs that are legal C but not
>> legal C++.  There are an infinite number of programs that are legal
>> in both languages but exhibit different behavior.  The two
>> languages continue to diverge as time goes on.
>
> That's true, modulo providing a definition of "legal" (neither
> standard uses that term).
>
> In order to make this more meaningful, I'm going to talk about
> compatible implementations of C and C++, a term that I need to
> define.  An implementation of C and an implementation of C++ are
> compatible if, for any given construct, if the meaning or behavior
> permitted by the C standard for that construct has any overlap
> with the meaning or behavior permitted by the C++ standard for
> that same construct, both implementations will give that construct
> the same meaning or behavior.
>
> The fact that both sets are infinite obscures an important point.
> Rather than looking at infinite sets, lets look at finite ones.
> Consider sequences of no more than N characters from the basic
> source character set.
>
> A sub-set C(N) of those sequences qualify as having no syntax
> errors, constraint violations or undefined behavior according to
> the C standard.  This sub-set can be further sub-divided into
> equivalence classes, every member of which has the same observable
> behavior under a given implementation of C for all possible
> inputs.
>
> A subset CPP(N) of all sequences of length N or less qualifies as
> well-formed code having no syntax errors or undefined behavior
> according to the C++ standard.
>
> Note that, in both subsets, I'm including programs with unspecified
> behavior.
>
> I believe that, for the overwhelming majority of the equivalence
> classes of C(N), there's at least one member of that class that is
> also in CPP(N), and which has the same observable behavior if
> compiled using a compatible implementation of C++.  Those members
> might qualify as poorly-written in either language, but they don't
> have any problems as far as the C standard is concerned.

There are several problems with this argument.

One, there is no evidence at all offered to say the statement of
belief is true.

Two, looking at any given C program, there is no way to know with
certainty that a corresponding equivalent C-and-C++ program
exists (in the sense of also satisfying the C(N) and CPP(N)
conditions).

Three, when looking at a particular C program and a proposed
candidate C-and-C++ program, there is no way to know with
certainty that the two programs are equivalent, because testing
for equivalence is undecidable.  So the hypothesis is probably
impossible to verify.

Four, the test suggested bears no obvious relationship to any of
the usual ways that programs are evaluated.  More briefly, the
test looks artificial.  Because of that it seems to have little
conceptual value.

Five, the test doesn't tell us very much because the criterion is
so weak.  Turing equivalence is a very coarse filter.  For
example, many Fortran programs can be transformed into an
equivalent Fortran program, of the same length, that is also a
well-formed and equivalent C program.  That doesn't mean C and
Fortran should be considered to be closely related languages.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Two different Results between C and C++ Real Troll <real.troll@trolls.com> - 2020-06-02 04:08 -1000
  Re: Two different Results between C and C++ mark.bluemel@gmail.com - 2020-06-02 07:59 -0700
    Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-02 09:26 -0700
      Re: Two different Results between C and C++ Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-06-02 12:41 -0400
        Re: Two different Results between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-06-02 18:09 +0100
        Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-02 11:51 -0700
          Re: Two different Results between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-06-02 20:44 +0100
            Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-02 12:59 -0700
        Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-02 16:06 -0400
          Re: Two different Results between C and C++ mark.bluemel@gmail.com - 2020-06-03 00:27 -0700
  Re: Two different Results between C and C++ John Bode <jfbode1029@gmail.com> - 2020-06-02 08:41 -0700
    Re: Two different Results between C and C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-06-02 09:20 -0700
    Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-02 12:36 -0400
      Re: Two different Results between C and C++ John Bode <jfbode1029@gmail.com> - 2020-06-02 11:39 -0700
        Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-02 12:06 -0700
          Re: Two different Results between C and C++ Richard Damon <Richard@Damon-Family.org> - 2020-06-02 15:41 -0400
            Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-02 13:50 -0700
          Re: Two different Results between C and C++ John Bode <jfbode1029@gmail.com> - 2020-06-04 13:16 -0700
            Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-04 16:41 -0400
            Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-04 16:04 -0700
          Re: Two different Results between C and C++ raltbos@xs4all.nl (Richard Bos) - 2020-06-04 20:47 +0000
            Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-04 17:35 -0400
              Re: Two different Results between C and C++ raltbos@xs4all.nl (Richard Bos) - 2020-06-04 22:01 +0000
                Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-04 20:11 -0400
            Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-04 16:10 -0700
              Re: Two different Results between C and C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-06-05 02:26 -0700
                Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-05 11:33 -0700
              Re: Two different Results between C and C++ Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-06-05 11:28 +0000
          Re: Two different Results between C and C++ Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-06-21 00:53 -0700
            Re: Two different Results between C and C++ Öö Tiib <ootiib@hot.ee> - 2020-06-21 03:57 -0700
            Re: Two different Results between C and C++ Richard Damon <Richard@Damon-Family.org> - 2020-06-21 08:08 -0400
              Re: Two different Results between C and C++ Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-06-28 04:59 -0700
            Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-21 10:59 -0700
            Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-21 11:40 -0700
              Re: Two different Results between C and C++ Richard Damon <Richard@Damon-Family.org> - 2020-06-21 19:50 -0400
              Re: Two different Results between C and C++ raltbos@xs4all.nl (Richard Bos) - 2020-06-29 16:20 +0000
                Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-29 11:18 -0700
                Re: Two different Results between C and C++ raltbos@xs4all.nl (Richard Bos) - 2020-06-29 21:46 +0000
                Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-29 14:59 -0700
                Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-29 18:53 -0400
                Re: Two different Results between C and C++ Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2020-06-30 01:40 +0200
                Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-29 17:48 -0700
                Re: Two different Results between C and C++ David Brown <david.brown@hesbynett.no> - 2020-06-30 07:45 +0200
                Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-30 15:11 -0400
                Re: Two different Results between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-06-29 17:45 -0700
        Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-02 15:51 -0400
          Re: Two different Results between C and C++ Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-06-21 01:25 -0700
            Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-21 10:34 -0700
  Re: Two different Results between C and C++ Juha Nieminen <nospam@thanks.invalid> - 2020-06-02 18:45 +0000
    Re: Two different Results between C and C++ Bart <bc@freeuk.com> - 2020-06-02 19:55 +0100
      Re: Two different Results between C and C++ Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-06-02 15:11 -0400
        Re: Two different Results between C and C++ Melzzzzz <Melzzzzz@zzzzz.com> - 2020-06-02 20:14 +0000
          Re: Two different Results between C and C++ Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-06-02 16:19 -0400
    Re: Two different Results between C and C++ Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-06-02 15:06 -0400
    Re: Two different Results between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-06-02 16:20 -0400
  Re: Two different Results between C and C++ Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2020-06-06 00:07 -0400

csiph-web