Live data from Hacker News

C++ is not a superset of C

mcla.ug

21–30 of 114 posts

Re: C++ is not a superset of C

#21

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.

And 90% of those posts are made by beginners with a crashing linked list implementation. They're uninformed.

Re: C++ is not a superset of C

#25
post #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...

This is all totally fair -- I've never used restrict, so it's hard for me to have a useful opinion on it.

I think it's easy to dismiss things that can help optimisation when you've never seen their effect first-hand. I imagine if I'd had an experience where I'd used it to great advantage I'd be wishing it was in the C++ standard too :)

Re: C++ is not a superset of C

#28

Nit: memmove allows src and dst to overlap while memcpy does not.

Ah yes, what I meant was that more optimisations can be made on memmove if we restrict src and dst, as the overlap case no longer needs to be considered.

I've never used restrict, so I could be missing something, but this is what I meant in the blog post by mentioning memmove.

Re: C++ is not a superset of C

#29
The C++ specification has an entire appendix devoting to listing incompatibilities with C. Some features missing from this list:

* A char literal is an expression of type int in C, but type char in C++.

* String literals are const in C++ but non-const in C (although attempts to modify them are undefined behavior).

* This program is legal C but not C++:

   int i;
   int i;
* structs and unions occupy a different name space in C than they do in C++.

* main cannot be recursive in C++, but it can in C.

* C++ allows lvalues in a few more places. Usually, this amounts to a compiler error, but there are a few places where the additional lvalue-to-rvalue conversion is legal and produces a different result.

* There are some cases where C++ requires an explicit cast that C permits an implicit cast (void* being the most well-known)

Re: C++ is not a superset of C

#30

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 thought it was until just now. I've never done anything of substance in either, but I've tried both. Now I'm wondering if it was something I heard, or if I just assumed based on my extremely limited experience with both languages.
Post reply on HN