Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Bo Persson Newsgroups: comp.lang.c++ Subject: Re: Differences between C and C++ Date: Wed, 27 Jul 2022 19:28:15 +0200 Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net c0Op2oYTx7mqzRlk/Ij8ZAyidOGAVysN8DW/fWpXfF/HVwaBzg Cancel-Lock: sha1:fx9GzOACU+3+TiSUoRSoO24SXYo= User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: sv In-Reply-To: Xref: csiph.com comp.lang.c++:85695 On 2022-07-27 at 19:09, Paul N wrote: > On Monday, July 25, 2022 at 2:14:50 PM UTC+1, Juha Nieminen wrote: >> Some people often object if someone conflates C and C++, as if C++ were >> just a pure superset of C, pointing out that they are, in fact, different >> languages and, in some aspects, actually incompatible with each other. >> >> That got me thinking: What are all the differences between the two >> languages, in behavior and meaning, when it comes to their common syntax? >> In other words, I'm not here talking about different keywords and different >> syntax that compiles in one but not the other. I'm talking about code that >> does compile as both C and C++, but will be interpreted or behave >> differently depending on which (and this makes them incompatible). > > As I understand it, the two languages have quite different philosophies. In BCPL there is a stated aim of eliminating hidden overhead. There seems nothing in the history of C to suggest that this aim was dropped, certainly B was developed on a very spartan machine. In contrast the aim in C++ is to try to hide the underlying details. Yes, we call that abstraction. :-) Bjarne uses an onion as his metafor. We don't want to see all the way to the core all the time. > > For example, in C, a = b + c is a straight-forward addition, though depending on the types it might be a floating-point addition or it might involve a hidden multiplication by a pointer size. In C++, a = b + c could be anything - for instance, it might concatenate two files to form a third one, involving thousands of disk accesses. I have never understood why this is a problem. In C you can write a = add(b, c) and it can do anything. How is that easier to see through than using the + operator?