The relationship between C and C ++

When Stroustroup was developing C ++, one of its goals was that C ++ was as superset of C as possible. I understand that this is not 100%, but most of the good C code is also C ++ code.

But I heard that C99 supports many things that C ++ does not do (like VLA), and that there will even be C1x or C0x, whatever it calls. So, C ++ is a superset of only the old C89, and from now on do C and C ++ evolve almost independently of each other?

+8
c ++ c compatibility
source share
6 answers

C ++ is almost a superset of the C89 / C90. (I do not recommend writing code to compile it as C or C ++.) Since then, C99 has diverged. The new C ++ standard (often called C ++ 0x) will have some attempt to be more compatible, but will not have such things as variable-length arrays of C99. Straustrup expressed disappointment with some of the activities of Committee C, obviously expecting them to try to get closer to compatibility with C ++.

So yes, the languages ​​diverge.

+7
source share

It is right. C ++ started out as a superset of C when it was originally developed. Since then, they have grown independently of each other.

+4
source share

There is a concerted effort to maintain language compatibility as practical as possible, and C ++ 0x will accept some C99 changes. But it is likely that they disagree to some extent, with the VLA being the most noticeable discrepancy. I do not know that C ++ will accept restrict .

+3
source share

An interesting article by Bjarne Stroustrup that sheds some light on this topic: Sibling Rivalry: C and C ++ (pdf)

+3
source share

Even for old C, aka C89, under the hood, the difference is difficult to handle, returns from operators that are lvalue for one, and not for the other, a control thread that is valid for one and not the other, etc. Where they are ok is at the interface level for functions with prototypes, struct , etc.

For a newer version of languages, this diverges even more, since even interface compatibility can be difficult to maintain. C99 already has a static for limiting the parameters of an array function, the concepts of compile-time constants vary greatly in both languages, C ++ starts reusing old keywords ( auto ) and excessively uses new keywords that are not in the reserved namespace .. .

So, I think the gap will widen, and it is probably better for both communities to recognize the divorce and try to come to an agreement separately.

+1
source share

but most of the good code in C is also C ++ code.

Not.

I would say that the best C code compiles using the C ++ compiler.
This does not make C ++ code.

C ++ is a superset of only the old C89, and from now on do C and C ++ evolve almost independently from each other?

C ++ was based on C89.
C was expanded with C99, very few of which were included in C ++ 03
Currently, efforts are being made to minimize the difference and approximate languages ​​(where reasonable) for C ++ 0x

+1
source share

Source: https://habr.com/ru/post/649943/


All Articles