Linked by Thom Holwerda on Tue 12th Oct 2010 21:52 UTC
Java "Oracle and IBM today announced that the companies will collaborate to allow developers and customers to build and innovate based on existing Java investments and the OpenJDK reference implementation. Specifically, the companies will collaborate in the OpenJDK community to develop the leading open source Java environment."
Thread beginning with comment 445026
To view parent comment, click here.
To read all comments associated with this story, please click here.
Member since:

The question is why would you bother to use C to emulate C++ (unless you have to for some reason, e.g. for backward compatibility or to work around compiler limitations)?

Of the top of my head:
1. You only need a small subset of CPP OO capabilities (objects), but rather not get hit by the CPP compiler limitations. (E.g. strong types)
2. Memory allocation under CPP is abysmal, at best. (Even if you take the time to replace the new implementation with your own, you still cannot replace informative error codes...)
3. Class constructor (and destructor) are poorly designed (lack of informative error codes), forcing you to use C-like initialization functions.
4. I work in environments (such as kernels) that do no look kindly at linking against the CPP rt libraries, let alone using exceptions (!!!!!) as error handling mechanism...

In short, if you only require objects and limited inheritance, good C implementation is far superior compared to full fledged implementation CPP. (And don't get me started about STL!)

In the world where web apps are barely secure even though they are written in high level languages like Java, the last thing we need it to return to buffer overflows, dangling pointers, etc.

I fully agree. As I said, I didn't really agree with the OP.

- Gilboa

Reply Parent Score: 2

drstorm Member since:

All valid points. ;)

Reply Parent Score: 2

Neolander Member since:

Well, Stourstrup himself said that there's not a single favored way to use C++, and that not using every feature is not a crime or characterized incompetence.

In my case (kernel development), I currently use it as a very nice superset of C with classes and (very important) function and operator overloading. I also use references from time to time. That's it.

In that case, the sole runtime requirement is to run the constructors before the kernel. Not a big deal, the assembly snippet required in order to do that is only a few lines long.

Reply Parent Score: 2

gilboa Member since:

... Than again, I must wonder, what's the use?
If you cannot use:
- operators (kernel code that cannot be debugged by reading it is a big no-no in my view).
- virtual functions (as above, plus, they may hide a major performance hit due to unknown vtables depth/size).
- You are forced to write your own per-class init and close functions (lack of constructor and destructor error code).
- You are forced to re-implement new (over, say kmalloc, with some type of fancy error code management).

In the end, you're only left with objects and partial inheritance - or in-short, you more-or-less get an automated "this" pointer.

Call me crazy, but IMO, it's far easier to implement objects in pure C. (As it's already being done, quite successfully, in the Linux kernel)

P.S. Which kernel are you using?

- Gilboa

Edited 2010-10-14 22:42 UTC

Reply Parent Score: 2