C++ is not a superset of C
61–70 of 114 posts
Re: C++ is not a superset of C
#62Nearly 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/
Are they trying to make C literally become the same as C++ except classes and templates?
Re: C++ is not a superset of C
#63Nearly 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/
Now thats exciting
Re: C++ is not a superset of C
#64Earlier quoted context omitted.
> Are they trying to make C literally become the same as C++ except classes and templates? As a C programmer, aren't classes, templates, and exceptions the things that have classically differentiated C and C++?[0] I don't see anything obviously objectionable about nullptr[1], auto, __has_include, or constexpr. (I don't have a ton of experience with them, either.) I'll admit I don't really grok what "make false and tr…
They're not the "problems" with C++, they're what make C++ great. It's like C is slowly realizing C++ features are actually useful, but doing so as slowly as molasses, while still trying to pretend like this isn't the case...
We're going to have to agree to disagree on that one.
> It's like C is slowly realizing C++ features are actually useful, but doing so as slowly as molasses, while still trying to pretend like this isn't the case...
I think it makes sense to adopt C++ features that do some combination of (1) providing a useful feature, (2) aiding C++ compatibility, and (3) not majorly increasing the conceptual size of the C language. Just like it makes sense for C++ to adopt C99-compatibility (structure literals has taken y'all like 20+ years to adopt).
Templates, classes, and exceptions are a huge huge addition to the complexity of the language. If C programmers wanted them, with all of the pitfalls of manual memory management and C-style lifetime safety, they'd just use C++. Obviously, they don't.
Personally, if I had to choose a language other than C I'd pick something like Zig, Rust, or Go over C++.
Re: C++ is not a superset of C
#65Designated initializers were added in c++20, I was just looking at a recent change to clang's semantic analysis that warns on the differences between C99 and C++20 designated initializers (Todo: post link when not mobile.) One recent difference I saw was valid in (via GNU C extension) but invalid in c++: struct foo my_foo = ({ init(&my_foo); my_foo; });
Re: C++ is not a superset of C
#66Earlier quoted context omitted.
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.
Have you seen practical cases where there has been issues because C code is not compatible with C++? The blog has nice toy examples, but would be nice to know if they actually occur in the wild.
Off the top of my head, I've run into:
- C++ does not support 'foo([static N])' function declarations
- C++ does not support 'struct A a = { .b = c, ... }' initializers
The conflict arises when these are used in C headers, and then C++ programs attempt to include them.
Re: C++ is not a superset of C
#67This 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).
I am hoping this isn’t an implication that C is legacy and C++ is the modern and the future. :-)
Re: C++ is not a superset of C
#68Earlier quoted context omitted.
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
#69Earlier quoted context omitted.
I am hoping this isn’t an implication that C is legacy and C++ is the modern and the future. :-)
Not that I've worked in a lot of places, but everywhere that I've worked that uses C at all treats it this way. Writing new C code is considered a no-no.
Re: C++ is not a superset of C
#70Nearly 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/
"Add a type aware print utility with format specification syntax similar to python" Now thats exciting