Blog: Post-Incrementing the C

Here you can discuss ReactOS related topics.

Moderator: Moderator Team

Post Reply
Z98
Release Engineer
Posts: 3379
Joined: Tue May 02, 2006 8:16 pm
Contact:

Blog: Post-Incrementing the C

Post by Z98 » Mon Nov 10, 2014 6:23 pm


Konata
Posts: 391
Joined: Sun Apr 20, 2014 8:54 pm

Re: Blog: Post-Incrementing the C

Post by Konata » Mon Nov 10, 2014 9:26 pm

That title made me smirk

As I like to say, any sufficiently advanced C program becomes a C++ program, either accidentally or explicitly ;) I call it Greenspun's Ninth Rule

Oddjob64
Posts: 40
Joined: Sun Jun 01, 2014 10:21 am

Re: Blog: Post-Incrementing the C

Post by Oddjob64 » Tue Nov 11, 2014 4:32 am

I guess programing just got a lot more convenient, and the shell only got a little slower.

gigaherz
Posts: 92
Joined: Sat Jan 21, 2006 9:26 pm

Re: Blog: Post-Incrementing the C

Post by gigaherz » Tue Nov 11, 2014 6:46 pm

Oddjob64 wrote:I guess programing just got a lot more convenient, and the shell only got a little slower.
It's a common misconception that using C++ automatically makes things slower than the equivalent code in C. There is a small overhead in the code, yes, but most of it is due to misusing virtual functions (indirect calls), and not being aware of the "this" pointer parameter implicit to instance methods. But since all this code was already COM code, which means it was implementing virtual functions (indirect calls to functions pointers through the vftable) even when using C, you have the same exact indirect calls and this pointer parameters as before! So there is no reason why the C++ conversion made anything slower at all, just easier to read.

EDIT: If you were thinking that C++ code is harder to optimize by the compiler, keep in mind two things. First, that is only true for highly convoluted code that would also be hard to read by the programmer. Second, that ReactOS doesn't really use compiler optimizations yet, as they would introduce extra variables (as in external factors, not data containers) making debugging harder -- so it's not going to optimize the C code either.

Konata
Posts: 391
Joined: Sun Apr 20, 2014 8:54 pm

Re: Blog: Post-Incrementing the C

Post by Konata » Tue Nov 11, 2014 8:35 pm

Oddjob64 wrote:I guess programing just got a lot more convenient, and the shell only got a little slower.
Actually, not only do modern compilers generate code that is indistinguishable from C equivalent, I've written some programs in C++ that are faster than their C equivalent. I think this misconception arises from bad programmers attempting to use a lot of C++'s features without actually any concern for how they'll impact performance. A well-written C++ program can run extremely fast. Take Haiku for instance, I think it boots quicker than ROS (totally different architectures I know, but the point is it's fast).

Post Reply

Who is online

Users browsing this forum: DotBot [Crawler] and 2 guests