• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

The following article threads are reserved for forum material only:
• Selected C Topics
• Tricks and Techniques
• Algorithms in C

##### Share on other sites
RE: C vs C++

This post is a bit of a question and a bit of a catalyst for comment and discussion. Let me set the scene: I, like most people, originally learned programming in procedural languages. Eventually I learned object-oriented programming by way of C++, though I didn't have much time to spend on it before my career took me into Python and Java.

Both Python and Java were a joy to program in, and I became more and more adept over the years at thinking of software architecture in very object-oriented terms.

Now that I'm sitting back down in front of Visual C++ to program games, I've hit the obvious question of "C vs C++" which Teej wrote about. For me, programming games in C++ only seems to make sense. I start to think of the architecture of a game or a game engine and I see objects that represent in-game objects, game rules, interfaces to DirectX (or any other library I wanted to use, making cross-platform development easier), etc. I see these objects talking to one another though implementation-independent interfaces. I see some of them running simultaneously inside of their own threads, communicating via messages. In my mind, it looks beautiful.

Is my vision unattainable? Is it simply naive? After having been spoiled by the lush and powerful OOP stylings of both Java and Python, I find that C++ feels clunky and awkward by comparison. This is obviously due in part to my relative "rustiness" with C++, but it's not something I felt with the other languages.

Is this an argument against the use of C++? Perhaps. But, for me, it also seems an argument against the use of C. Now that I have this vision of OOP game development, I find it hard to conjure a similar vision in procedural terms. Each time I try, it, too, seems awkward and clunky. I feel like there's so much more that I can get out of C++. If I were programming for the Palm Pilot I can see where C would work beautifully. But I have all this computing power in front of me -- is object overhead really that cumbersome? Isn't it negligible, especially considering the benefits it provides, both in what it allows you to do and how it allows you to do it?

I'm not advocating the forum use C++, but I'd love to hear any comments people have on this.

Edited by - silicon_jesus on April 28, 2001 8:24:06 AM

##### Share on other sites
I prefer C++ to C, even though I don't have much experience with C and I don't have terribly extensive experience with C++. The bonus of C++ versus C, to me, is that you can do everything that C can do, only easier. You don't need to change your style of thinking in order to incorporate object oriented program, because C++ isn't completely object oriented. I do agree with Teej's choice of C for a "Beginners" tutorial, though. It seems like virtual functions, friend functions, inheritance, opperator overloading, etc, etc, would cause any games that we created to become more complex, and less easy to understand for people who haven't had any experience using them before. Using C++ without the complex functions, however, would be a waste, as you'd be practically programming in C anyway.

Silicon: All of the things you listed sound definately possible, (although I hear multi-threading is complicated in C++, it is definately possible). A lot of people don't like C++ as much as they do Java because Java is more object oriented and it removes a large amount of the more complicated things that C/C++ deal with. What I've heard about Java is that it can do all of the things that C++ can do and vice-versa, but it is easier to manage at the price of a small amount of control. I don't know if this is true, as I'm a novice C++ programmer at best and I have no Java experience, but I definately think that you should stick with C++.

Edited by - RandomGamer on May 2, 2001 4:49:00 PM

##### Share on other sites
It seems to me that programming games before you can write simple programs is like putting the cart before the horse. Frankly, if you can''t write a computer program, then you are going to become very frustrated trying to write a computer game.

Many of the problems that people have posted suggest that they should really go back to square one and get a few basic books on programming fundamentals. When they understand how to deal with basic things like linker and compile errors, and are able to create the kind of programs that introductory books deal with, then they will be ready to write really simple, 2-D games.

I apologize if you find this post discouraging; BUT, writing a computer game is NOT a good way to learn how to program.

##### Share on other sites
I would like to say that C++ is not just "C with classes". I still makes a lot of "modular" programming when I create games but I don''t go back to C. When I first learned C++, I was thinking that C was just "C++ without classes" but it''s not true, there is a lot details that are changed. For example, in C++, we don''t see this kind of instruction:
typedef struct tagPoint {
int x;
int y;
} Point;
...because we don''t need to repeat "struct" with each Point declaration. Many people think that they are programming in C while they compile with a C++ compiler (mostly visual c++) and use a lot of the C++ improvements.

##### Share on other sites
Here are three excellent references for programming in C++:

(1) "Thinking in C++" 2nd edition (vol. 1 & 2) by Bruce Eckel. These FREE, on-line books are available from www.mindview.net.

(2) C++ Primer Plus by Stephen Prata (Waite Group Press). List price for the hardcover edition is about U.S. $49.99. (3) C++ How to Program - Introducing Object-Oriented Design with the UML" 3rd edition by Deitel and Deitel. List price is about U.S.$(one arm and a leg).

If you master any one of these books, you will be a proficient C++ programmer. If you are a beginner and have deep pockets, I recommend (3) above - it is first class (and the price reflects the quality).

Programming in C/C++ and programming Windows applications are two different things. Once you can program in C or C++, you can apply your skills to developing Windows applications. Here are two recommendations:

(1) "Programming Windows" 5th edition by Charles Petzold. This is the "classic" book on Windows programming.

(2) "Tricks of the Windows Game Programming Gurus" by Andre Lamothe. If you know how to program elementary applications in C or C++, this book will help you to apply your knowledge to Windows and to develop 2-D games.

##### Share on other sites
Alexk7: I agree that the line between C and C++ is blurred; moreso than I let on in the article. As you could imagine, this article was a pain to write because of all the ''flowers in the garden getting trampled on'' in the process. It''s easier to simplify and call C modular and C++ OOP, even though it''s closer to the truth to say that C today is merely C++ without using function pointers in structs (or classes). I don''t think you''ll find a C programmer not using ''//'' for comments, even though it''s a C++ addition.

C is the easier language to start out with in game development, and C++ becomes more of an ideal when the game code gets large and unweildy. I myself wonder at times if the overhead involved in using virtual functions etc. is really that much of a consideration anymore, and I''m sure that most of us deep down would rather go the OOP way in the end (minus some of the craziness that goes on with more complicated facets of the language).

There is one factor however that I can''t overlook for the time being, and it''s a side-effect of programming in C++ and the way we apply our abstract thinking... we make little mental rules on how classes act together and how other classes arbitrate their communication, and what ends up happening (almost always) is that there''s an inherint increase in overall traffic. Umm, how do I describe it? Well, for instance, the calling method validates data on its end, and the callee again validates the incoming data. State information needs to be validated because of the nature of objects in general, and it''s the overall etiquitte that we throw into our object coding that introduces so many extraneous calls. This is the nature of the beast I''m afraid, and it''s one of those overlooked ''wrenches'' in the paradigm.

I will say one thing -- I use C++ for damned-near everything except for game development. Perhaps I need to take that final leap myself...

Teej

##### Share on other sites
i aint been having luck with extern, ill decxlare it in two.cpp and make it 12, then i''ll include two.cpp, in one i''ll do extern int i, then ill do a printf, and it comes up as 0.

-kaptan

"If you cant handle the heat, Get off the car hood"

##### Share on other sites
sorry to waste space, i fixed the other problem, but why do i get unresolved externals sometimes, sometimes it happens when i make a new project, sometimes when i make a new source file and let the compiler ask me to make a project and i selct yes, its odd well thanx.

##### Share on other sites
RE: C v C++

I have been struggling with this for a while as well. I think that what i have decided is this: C is obviously faster and easier to learn/use in a lot of case. C++ is more controlable and better when projects get larger. So, why not just use C++ when it is to your advantage(i.e. classes) and use C when it is to your advantage(i.e. speed)?

##### Share on other sites
In the context of this forum (i.e., creating relatively simple, 2-D games), speed is not an issue when deciding whether to use C or C++. Also, C is only simpler than C++ when you are talking about very simple programs.

##### Share on other sites
Hi everybody

I don't know if I am posting at the correct place.
I also want to learn "how to develop a game". But here are some harsh facts which obvously won't help me:

(1) I learnt C++ with Unix as backhand 3yrs. ago & though I have forgotten everything still I believe I can recover it.
(2) So besides (1) there is nothing which can help me in game programming...so I have to start from begining.

I am more interested in Console Game programming than PC game programming & I believe both are different in terms of programming languages, programming techniques etc etc..& whcich one is more difficult.

So what languages are necessary in order to program for consoles ...where to start/how to start? I know it isn't an easy thing..but game is still not over.

My email add. is deepak_tamang@yahoo.com, so if anyone can help me...or guide me.....

Edited by - deepak tamang on May 14, 2001 6:43:54 AM

##### Share on other sites
RE: C vs. C++ vs. JAVA
Hi, I have been learning JAVA for a year now. I have some insights in C but noh C++.
After I switched from C to JAVA it was like HEAVEN!
The problem that however is a big one is the speed and also it is some say it is very high level. I was wondering is there any Language with the Simplicity of JAVA and power of C++ for ex?
Also I have to agree with above post''s that OOP is the best way to design/programm any kind of idea you may have. Thinking in terms of OOP is just TOO natural for human beign, that is why I think I(we) tend to like it that much.
I do not know much C++ but from a glipmses of it, it seems like nightmare(of course).
I have been programming in JAVA and now that I have read this Forum I find ALOT of similarities(double buffering ie.) with other languages. However after reading this forums I have become discouraged in JAVA, and now am deciding to pursue C and ultimately C++. Does anyone have a similar expirience? Appreciate it.

PS: sory for LONG letter and perphaps(newbie) content.

-SKULLZ

##### Share on other sites
By the way... is Python any good? I mean is it faster than JAVA at least?

-SKULLZ

##### Share on other sites
Think of it this way. If you think of programmers as belonging to ''families'' where each language has it''s own community, and you want to be a part of the largest, most powerful family in the computer industry, join the C/C++ club. Here are some of the rewards of membership:
• Part of the largest following on earth, meaning that there are more resources available for C/C++ than any other language

• Tradition. C is the fundamental backbone language of everything you use, from embedded systems to games on all consoles and platforms, right down to the operating system you''re sitting on. The language has proven itself throughout the years and isn''t going anywhere.

• Power. Any language that''s ideal for everything from mission-critical low-level code to enterprise systems has everything a programmer needs for any task -- like having the largest toolbelt around your waist. You can get right down to the machine''s level and squeeze cycles out of it, or work at your own level comfortable in the knowledge that today''s C/C++ compilers know exactly how to pump out lean and mean code.

• Versatility. A competent C/C++ programmer doesn''t need to learn anything else to be given a challenge and produce compact, fast, efficient code that meets any requirement.

• "Accepted Worldwide." If you tell someone you''re a programmer, they''re either going to assume C/C++, or ask something like, "In C/C++, right?" Take what you will from that.

• Help is everywhere. Because of the language''s popularity and seniority, countless material, resources and assistance is available for working something out in the language.

When I think about programming, and all of the languages out there (BTW I program in C/C++, VB, Java at work daily), it isn''t even a choice for me when I want to start writing something new. I pull out my MSVC, create a new project, and hesitate for a brief moment before the blank page, and I swear that a small smile starts to form on the edge of my lips, for I can feel the power at my fingertips when I''m about to feed the computer something in a language it obeys with its undivided attention.

And the computer has no idea what I''m about to tell it, for it could be anything. It will work, it will be fast, and it will harness the complete power of the machine it''s on.

God, I love C/C++. You should join the family; it''s a good feeling.

Teej

##### Share on other sites
I''m not sure where I should post this, but I figured it would be useful. I noticed that on my system there is a DirectX control in the control panels. When I clicked on the DirectDraw Tab, there was a control box that showed the available screen modes, and next to each one that is 16 bits it has a (565). This might be helpful to those who might be unsure as to what their system used. Also, I downloaded the windows version of The Gimp, and I love it. Photoshop be damned.

##### Share on other sites
Hi,

In order to have a btter understanding of what DX worls and how to use it, I bought a book on it at the local library.
"Teach yourself DirectX7 in 24 Hours"

How wonderful. . .

Problem is that I get stuck in the first example on a simple thing they simply pass over. . . Resource files.

I''m going to go in much detail so you guys can tell me where I went wrong.

ok, for starters, here''s the code they provide (simple tool bar on top with a Quit command in the file menu):

//resourcescript.rc
#include "resource.h"

BEGIN
POPUP "&File"
BEGIN
END
END
//End Of File

//Resource.h
#define IDM_EXIT 40001
//End Of File

Now, I didnt know anything about resources files so I tried a couple of things. . .

I first thought it would be nice to make a new file. I hit File-->New-->Files-->Resource Script
This managed to create an entry in the Resources Tab(between the files and class tab). . .so far so good.

This is where I get lost. . .
When in the resource tab, in the window where I usually type my code, there''s a folder with the name of my resource script.
the only thing I can do is to right-click on it and add symbols or include stuff. . .

So, I''m kinda lost there. . .
Ican add the file and quit thingies but I really dont know muh about the option listed in those checkboxes.
I dont know how to make the quit work either (when clicked on, this is supposed to close the DX application running)

So, what I did next was to go directly in my workspace folder and ooppen my resourcescript.rc in a text editor.
I''ve seen there that the genrated code wasnt similar to the one I typed above. . .

So i typed this same code directly in the text editor and saved it as a .rc file. . .
On compile, it seemed it would get errors in the .h file with those numbers after the includes (ie 102 and 40001)

So I''m at loss there. . .I dont know what else to try.

Could any one else give me a detailed insight or tutorial or webpage adress to help me?

thanks
Diabolus

Ð!@ßØ£Ü§