4 ms·
While it isn't a strict superset, there aren't any C features you can't use in C++, unless you count lack of pointer type safety as a feature. This was the orig
by pmjordan 14y ago
While it isn't a strict superset, there aren't any C features you can't use in C++, unless you count lack of pointer type safety as a feature. This was the original point I was making (and note how I didn't say it was an actual superset).
- __david__ 14y agoOf course there are: C99 initializers are heavenly and they don't exist in C++.
- deleted 14y ago[deleted]
- dlsspy 14y agoThe two ways (C90 and C99) you can create a variable length item at the end of a structure in C are invalid C++. You can't express them at all. I work around it by making a one element array and using "sizeof(MyThing) - 1" everywhere when I want to reference the size then use placement new and the ::new operator to do the allocation and initialization of my object. It works, but it's not very straightforward. In general, I rather like C++, but it does make a few things harder than C.
- ajross 14y agoYou can't do it for structure fields in C++. The C++ idiom would probably be something like a member function that returned (void*)&this[1].
- dap 14y agoYes -- see my post above. Syntax and semantics simple enough to be easily statically analyzed (both by humans and tools like lint) are a language feature that C has over C++. More generally, many people see significant value in the very property of C that it doesn't let you do things that C++ lets you do. That's why the argument that "C++ is a superset" and "there's no good reason not to simply use a C++ compiler on your C code" is bogus.
- deleted 14y ago[deleted]