Hacker News new | ask | show | jobs
by jpmec 4610 days ago
I was objecting to filling "all" the domains. I was referring to classes as inherently C++. For example, constructors, destructors, virtual functions, namespaces.

For example, AFAIK you cannot have a naked struct in C++. A struct is a class, and therefore can have methods, thus can have constructor and destructor.

Also, exceptions are a big part of C++ that I don't think you can remove?

If you want simple, obvious separation of data and logic, and you don't want exceptions or name mangling, then C is probably a better choice for that domain.

I like C++, but it is not C and is unlikely that one will ever replace the other in all the domains.

OTOH, if you want to write OO and you like C++, then it is not a bad choice.

I think both are being used to write new systems, so neither is legacy :-)

1 comments

> I was referring to classes as inherently C++. > AFAIK you cannot have a naked struct in C++

The "class" keyword and the "struct" keyword differ only in default member visibility. You're free to use the struct keyword. Yes, such structs can have member functions, but they change little except to act as a convenience. A "naked struct" in C++ is called a POD ("Plain Old Data") type, and there are a few rules to ensure your structure meets that definition. The standard library has a type trait to test a class/struct to see if it meets that definition (called std::is_pod).

> For example, constructors, destructors, virtual functions, namespaces.

None of these actually interfere with any use cases or domain that I can think of. Constructors and destructors are insanely valuable features, even if you use nothing else. Functions are not virtual by default and impose no overhead unless used.

> exceptions are a big part of C++ that I don't think you can remove?

You can turn exceptions off at the compiler level. -fno-exceptions in GCC and Clang. RTTI can also be disabled. Disabling both in embedded cases is perfectly reasonable.

> name mangling

extern "C" {} blocks kill name mangling and allow you to export a C API and ABI compatible function.