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


Groups > comp.lang.c > #152857

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 00:53 -0700
Organization A noiseless patient Spider
Message-ID <86d05skg6z.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> <87blm1wam0.fsf@nosuchdomain.example.com>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> John Bode <jfbode1029@gmail.com> writes:
>
>> 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.
>
> [...]
>
>> 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.
>
> There are also an infinite number of programs that are legal C and
> legal C++ with the same behavior.
>
> All these statements are true, but none are particularly relevant.
> You can construct an infinite number of valid C or C++ programs by
> playing games with the grammar.  There are an infinite number of
> legal C programs that use conditional operators nested 10,000 levels
> deep, but I doubt that any such programs exist in the wild (except
> *maybe* as compiler capacity tests).  I think it's more useful to
> look at actual code rather than contrived infinite sets of programs.
>
> There are *some* programs that are legal C but not legal C++.  The
> most common causes of this are probably C++'s tighter restrictions on
> implicit conversions involving void*, C code that uses C++ keywords
> as identifiers, and C features that haven't been incorporated into
> C++, such as VLAs, _Generic, and compound literals.  But almost all
> programs that are legal C but not legal C++ can be made into legal
> C++ with a small effort.

This claim sounds like an article of faith, being offered without
either proof or evidence.  If meant as just an empirical statement
then of course there is no way anyone can know that.

If we consider the set of finite and well-formed C programs (meaning
having no constraint violations or other compile-time errors), only
a vanishingly small fraction of those are also well-formed C++
programs.  This statement is mathematically precise in the sense
that the limit of the density goes to zero.

Furthermore, for any given amount of effort, the subset that can be
converted to well-formed and equivalent C++ with that effort or less
(including those that are already well-formed C++ and so take no
effort) is a vanishingly small fraction of the total, again in the
mathematically precise sense that the limit of the density goes to
zero.

So if we are going to make a statement about "almost all" C
programs, almost all C programs take more than a small effort to be
transformed into well-formed and equivalent C++, for any value of
"small effort" one might choose.


> There are *some* programs that are legal C and legal C++ with
> different behavior.  I don't think I've ever seen such a program
> that wasn't contrived for the purpose of making that point.

Probably you have but just didn't realize it.  Do you think you can
list all the ways that C programs can have a different meaning when
compiled as C++, even considering only those C programs that are
also well-formed C++?  Try it, you might be surprised by the
results.

>> So yeah, I'm going to continue to emphasize that they are different
>> languages with different rules and behavior, regardless of how much
>> they may have in common.
>
> Sure, they're different languages, but why ignore their
> commonalities?  [...]

Because in practice what the languages have in common is swamped by
their differences when considered in the context of real-world
programs.

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