Live data from Hacker News

C++ is not a superset of C

mcla.ug

11–20 of 114 posts

Re: C++ is not a superset of C

#11

I never heard anyone say that C++ is a superset of C. Sure, the first version was a preprocessor on top of C and certainly that is common knowledge. But a superset? Never heard it. ObjC on the other hand...

I've definitely heard c++ described this way.

Re: C++ is not a superset of C

#12
post #6

> The size of the array needs to be known at compile time. In C++, a const variable can be a constant expression, meaning it can be evaluated at compile time. In C, this is not the case, and we must instead use a pre-processor macro: Enums are also good here in C land for specifying compile time constants.

Yes, but only for constants of type int.

For example, this is valid:

    enum { ANSWER = 42 };
But C enumeration constants are always of type int, so you can't define a constant of some other integer type this way.

Re: C++ is not a superset of C

#13
This is true, but C++ is mostly a superset of C, which is "good enough" for the vast majority of developers. It's enough of a superset that we were able to seamlessly integrate our legacy C libraries with our modern C++ applications without hassle (and we didn't run into any of the corner cases listed in the article).

Re: C++ is not a superset of C

#15
post #10

Several of the examples shown as valid C are not. For example, this: const int foo = 1; int* bar = &foo; *bar = 2; is said to have undefined behavior, but in fact the initialization of `bar` is a constraint violation, requiring a diagnostic. (Some compilers will issue a non-fatal warning, which is allowed by the C standard but IMHO is unfortunate.) Another example: it says that this: const size_t buffer_size = 5; int…

Thanks, this is useful! I'll have to look at the standards again and be more precise in my language.

Re: C++ is not a superset of C

#16
post #11

I never heard anyone say that C++ is a superset of C. Sure, the first version was a preprocessor on top of C and certainly that is common knowledge. But a superset? Never heard it. ObjC on the other hand...

I've definitely heard c++ described this way.

It was a superset, once. C++ started as a C preprocessor. But the languages have diverged. It's enough of a superset, though, that C++ hasn't deleted bad features of C, like pointers and arrays being the same thing.

Re: C++ is not a superset of C

#17
Nearly everything that is mentioned in this blog is a subject of change / addition to the latest C standard, code named C2x.

They are in discussions to introduce the following in C:

    * nullptr
    * auto
    * __has_include
    * make false and true first-class language features
    * constexpr
and lots of other goodies [1].

https://gustedt.wordpress.com/2018/11/12/c2x/

Re: C++ is not a superset of C

#18

> I'm suspicious of restrict. It seems like playing with fire, and anecdotally it seems common to run into compiler optimisation bugs when using it because it's exercised so little. On the contrary, I wish C++ had restrict in the standard, for exactly the reasons mentioned: it can help the optimizer in certain cases.

Indeed, auto-vectorization usually won't work without it...

Re: C++ is not a superset of C

#19

I never heard anyone say that C++ is a superset of C. Sure, the first version was a preprocessor on top of C and certainly that is common knowledge. But a superset? Never heard it. ObjC on the other hand...

You evidently haven't been looking at the stackoverflow questions coming in at the [c] and [c++] tags... ;)

A frightening amount of [c][c++] tagging is expunged there every day.

Re: C++ is not a superset of C

#20

I never heard anyone say that C++ is a superset of C. Sure, the first version was a preprocessor on top of C and certainly that is common knowledge. But a superset? Never heard it. ObjC on the other hand...

I think it's quite a common thing for people to say if they're not actually experienced in writing the languages. I've heard it from multiple people.

As I say in the blog post, it's common knowledge for people who are experienced in writing C and/or C++ that this isn't true. But it's a misconception that persists among other programmers.

Post reply on HN