C Or C++


Hmmm, a GP2X emulator ? If you want to practice C and C++ the PC will work. To use something "like" the environment you COULD use cygwin (of course this is X86 but from a C/C++ point of view it would be the same) as long as you don't try to embedded any assembly language into the mix. There are SDL libraries for windows that you can use as well (to keep you somewhat independent from the hardware). Just remember that the memory is limited on the GP2X so any code you move over will have it code and data bonded by the available memory.
 
jukujin posted on Oct 18 2006 at 04:23 AM said:
C++ essentially is C with classes and dynamic memory management. Using the OOP approach available in C++ can make coding and debugging much, much easier. On standard computers I much prefer the OOP because of ease of use. It's easier to create a project in modules and debug individual modules than trace through a ton of linked code trying to find out where the bug is.

Dynamic memory management and OOP have some necessary memory overhead, however. If you really want to optimize your code, I would personally choose ANSI C (and adhere to strict ANSI). In a small program it probably won't matter much, but I don't have any experience programming for the GP2X (still need to buy one - waiting for a few more paychecks), so I don't know how much of an impact the OOP has on the hardware. It may be negligble, or it may totally depend on the scope of the project.

For learning programming, I think it's good to start with ANSI C. It's too easy not to understand what's actually behind the code, and a good understanding of C will help you avoid that. Then shift up to C++ and take advantage of OOP.
I've been reading "The C Programming Language" and am having a few problems with Bitwise operators ^^

At least if they'd mention they had started using Octal then it would of made it a whole lot easier to understand.
 
Last edited by a moderator:
The most important thing about learning C++, in my opinion, is to realize that all of the OOP stuff is nothing more than a series of compiler tricks. What this means is that every C++ program you write can be translated into an equivalent C program without any loss of functionality. Inheritance, polymorphism, encapsulation, references, templates; everything can be done in C, albeit in a pretty unwieldy way.

Once you realize this, you will start to learn how certain C++ constructions would work in C and what kind of impact they have on your program's performance. Normal inheritance, for instance, doesn't have any negative impact on memory or processing time. Polymorphism on the other hand, does cost more memory and CPU power. But why? What do these virtual functions actually do to your data structures? What kind of logic works behind them?

Here comes the point of my story; once you know the answer to all these questions, you will be able to safely use C++ and its better design capabilities, without having to fear for your program's performance all the time. Even on the more critical platforms, embedded systems such as the GP2X. After all, you can reason about what your program would look like in C and how it will perform in comparison.

Now, obviously this isn't something you will learn within a short period of time. I would certainly recommend getting to know C really well first, before starting out with C++. Working with a good debugger will also help a lot in learning the inner workings of your programs.
Looking at myself personally, I have slowly learned the ins and outs of C over the course of several years. After that, it took me about a year of regular work with C++ to learn most of its intricacies. Just take a look at this article that talks about member function pointers and explains how they work on different compilers. It has to be my favorite C++ article I've seen so far. It's just plain nuts.
 
Back
Top