Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Two different Results between C and C++ Date: Tue, 02 Jun 2020 12:06:47 -0700 Organization: None to speak of Lines: 72 Message-ID: <87blm1wam0.fsf@nosuchdomain.example.com> References: <8c6495f9-6139-464e-ac8f-4eac27a92776@googlegroups.com> <60d0f73c-8588-4673-a48d-e5c4cc726196@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="2b720ada2beb0fb974b5f9a3cdd89767"; logging-data="21394"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eI3qXabzlu553kFWmvnij" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:Un9JO6W9xmxMGzMkoXWSqvnC7+0= sha1:ETvfB8Iy67B6ctHLf753TbsfB8M= Xref: csiph.com comp.lang.c:152610 John Bode 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. 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. I can't think of a valid *non-contrived* reason to write sizeof 'A' or sizeof true, for example. > The two languages continue to diverge as > time goes on. True, but there is an effort by both committees to keep that divergence under control. > A well-written C++ program does not look or behave like a well-written C > program. The core philosophies and styles of the two languages are very > different. That I agree with. > 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? The relationship between C and C++ is *very* different from the relationship between, say, C and Fortran. (I have no problem with *emphasizing* the fact that they're different languages, especially in the context of discussing good C code vs. good C++ code.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */