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...
C++ is not a superset of C
11–20 of 114 posts
Re: C++ is not a superset of C
#12> 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.
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
#13Re: C++ is not a superset of C
#14const size_t buffer_size = 5; int buffer[buffer_size];
compiles fine in c, but not for the same reason. C99/C11 has dynamic arrays
Re: C++ is not a superset of C
#15Several 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…
Re: C++ is not a superset of C
#16I 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
#17They 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].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.
Re: C++ is not a superset of C
#19I 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...
A frightening amount of [c][c++] tagging is expunged there every day.
Re: C++ is not a superset of C
#20I 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...
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.