Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Two different Results between C and C++
Date: Fri, 04 Sep 2020 05:21:05 -0700
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <86o8ml7mxa.fsf@linuxsc.com>
References: <8c6495f9-6139-464e-ac8f-4eac27a92776@googlegroups.com> <60d0f73c-8588-4673-a48d-e5c4cc726196@googlegroups.com> <87blm1wam0.fsf@nosuchdomain.example.com> <86d05skg6z.fsf@linuxsc.com> <38c7640f-c674-4952-9af5-ce68f66b245co@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="7a5f90e0606212f607690ab7b970a5be"; logging-data="7823"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mDNGKzwUFX7y7YZa1bM7QiUx5lnQ9U+k="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:BMcCZ8KfGL5CvX/ZUzqIkTQe+zk= sha1:KKIhkxEVnsMxO5qumG3QhRAlyL0=
Xref: csiph.com comp.lang.c:154483
James Kuyper writes:
> On Sunday, June 21, 2020 at 3:53:49 AM UTC-4, Tim Rentsch wrote:
>
>> Keith Thompson writes:
>>
>>> John Bode writes:
>
> ...
>
>>>> 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.
>
> It neither an article of faith,
You cannot know that, since you don't know what Keith is
thinking.
> nor an empirical statement. It's a conclusion easily reached by
> anyone who knows both languages well enough to be aware of what
> needs to be done to make the conversion.
I still don't see any evidence being offered to support that
assertion.
> Knowing enough to reach
> that conclusion is made easier by the fact that Annex C of the C++
> standard provides what's supposed to be a comprehensive list of the
> relevant issues.
If you think that list is even close to being complete then you
really haven't been paying attention.
> If you don't think that it is comprehensive, it
> would be helpful to identify what's missing, incomplete, or
> incorrect in Annex C.
Have you even tried looking for other cases? Whether you have or
not, it's not my problem. The world does not revolve around you.
>> 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.
>
> Here's where we move from theory into empirical arguments. As a
> practical matter, I've done the relevant conversions many times, and
> it's trivial in most cases.
Considering what you said above, whether you have done so even
once is subject to doubt. If you don't know whether the end
result has the same semantics in C++ as in C, then you don't
know if the conversion has been accomplished.
> Your belief that it's usually quite
> difficult is something that I find quite mystifying.
It's not a statement of belief, it's a deduction. The deduction
is based on an understanding of the structure of language and
an understanding of the necessary mathematics (which actually
isn't all that much, but it is greater than zero). Did you make
any effort at all to follow the sketch I gave of the reasoning
underlying the deduction? If you did then was there something
about it that you didn't understand? Or, if you didn't, then
it isn't really surprising that you would be mystified by
an explanation you chose to ignore.