Page 1 of 1

From C++ to C - is/might it be worth it?

Posted: Mon Jun 01, 2015 2:31 pm
by makerimages
Hey, hmm. I need some opinions/advice. Regarding C++ and C. As you might know, my OS, entitled OS Zin is currently written in C++. Now I'm wondering, would it be worth to make a transition to C? As most OS's are made with C and so forth, and I'd really like to make (most) things POSIX compatible sometime. C also seems like a more of a easier language to code an OS in.

Re: From C++ to C - is/might it be worth it?

Posted: Mon Jun 01, 2015 3:09 pm
by JulienDarc
Maybe some will disagree, but if you don't plan to be running in the embedded world with massive size/space restriction, I think you can keep going with c++ (c++ == larger executables most of the time by experience, more dependencies as well).

But you can have a c'ish style in c++ and use some c++ features. I did that long ago (do not underestimate gcc's very powerful builtins if you plan to be gcc only).

I personally cannot stand c++ for all the things it does in your back and its unlimited list of pitfalls (and its syntax, and other old school things). But I digress. C++ is still a good language and you can keep it (some say Java is, too.. it all depends on YOU and the context your code will be running in).

Stay away from Boost.

As far as posix is concerned, why should it be a problem ? C++ is posix friendly too (but it may force some c'ish syntax).

Bye

Julien

Re: From C++ to C - is/might it be worth it?

Posted: Tue Jun 02, 2015 2:29 am
by GreaseMonkey
makerimages wrote:As you might know, my OS, entitled OS Zin is currently written in C++. Now I'm wondering, would it be worth to make a transition to C?
Unless C++ is actually giving you hell, no. Stick with what you're comfortable with, as long as it's not unnecessarily biting you in the arse.

This is reminding me of when AWOS moved from C to C++. I don't recall if we ever migrated it all back to C, or if the project was shelved before we had the chance.

Re: From C++ to C - is/might it be worth it?

Posted: Tue Jun 02, 2015 3:55 am
by Combuster
Size is only a concern if you use specific C++ features (primarily RTTI and exceptions) just once or twice instead of using them generously or alternatively disabling them, because that pulls in the language dependencies for relatively little use. C++ without runtime can still do a significant lot more than C.

Basically I would only recommend switching to a different language if you don't actually know C++ properly. C actually being "easier" is quite disputable, what is universally true is that the lack of C++ constructs make it a significantly bigger chore - and with that more error-prone.

Re: From C++ to C - is/might it be worth it?

Posted: Tue Jun 02, 2015 8:20 am
by JulienDarc
C++ without runtime can still do a significant lot more than C.
@Combuster : yes but you have to be very picky at the features you use. Generic programming may become size expensive. Virtuals, I/O streams, weird constructors (the two ways to construct an object), strings facilities, can be slow, operators override, plenty of misuses of setters/getters can lead to security concerns (and a lot of devs love setters and getters as you already know).
Multiple inheritance (if ever needed) can become hard to follow. Last but not least, compilation times. So many ptifalls.

You do very simple object oriented in C. With no surprises at runtime. But C still has a bearded geek reputation (not hype and seen as limited *in parties*).

Actually things can get much worse in c++. In C, you can definitely be slower than java if you don't know what you are doing but since it is a very simple language, more people can get involved and errors tend to be easier to spot (openssl aside).

On the other hand, C++ enables to save the developer time. And let the compiler to figure out that namespace/function overload/template (and so on). When coded properly (which requires some experience (more than in C)), it is a very good language.

@makerimages : honestly, don't bother.

Re: From C++ to C - is/might it be worth it?

Posted: Thu Jun 18, 2015 2:43 pm
by zehawk
makerimages wrote:Would it be worth to make a transition to C? As most OS's are made with C and so forth, and I'd really like to make (most) things POSIX compatible sometime. C also seems like a more of a easier language to code an OS in.
Yes and No. C is a lot easier in that a lot of the things in C++ limit what kind of tricks and hacks you can pull off. C allows void* variables, C++ does not for many compilers. C binaries can also (potentially!) have smaller sizes. The pitfalls with C is that it can certainly give too much power to the developer, and debugging code that used certain hacks and tricks can be difficult. C++ is definitely viable in OS development.

Another thing about C is that it is a much smaller step up from Assembly. Many C functions and operations can be almost directly mapped to Assembly instructions. (Not 1:1, but you know what I mean). C++ is not neccessarily so once you start dealing with classes and polymorphism. You might never use polymorphism in C++ OS development, but it's an example.

I'd say C would be worth it as sort of a learning experience sort of thing. It is less abstract than C++, but that depends how you use C++ in the first place. Not to mention that C compilers tend to be better optimized. (I can think of exceptions to this however.)

I will say that after you learn C for learning's sake, you will find that you can accomplish more things, but often at the cost of slower development time (Again, depends how C-like your C++ code was prior.) While not necessary to make a good OS, I would still learning C couldn't hurt.