• Advertisement

Archived

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

C or C++ ??

This topic is 2576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What are you guys using? Personaly, I think object-oriented design is the best way to approach the widest variety of game-related problems, but I can understand how many programmers would prefer the more straight-forward procedural approach, especially when system resources are tight. I''ve seen alot of your example code in VC++, but I haven''t seen anything that couldn''t be done in straight C (maybe I''ve been looking at the wrong code).

Share this post


Link to post
Share on other sites
Advertisement
well, i use normal c in my engine to make the .dll''s for the engine components .. but usually the game is in c++ .. since its object oriented...

i also use structs .. since they can be something like classes..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I use C. That does not mean that I hate C++. C++ is based on C, right?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Object Oriented Design != C++

Share this post


Link to post
Share on other sites
Classes are good to use. Its easy and gives a lot more reliability than normal procedural based programming. In information hiding classes are really helpful.

The program can be made good with classes and private and public variables are really helpful. struct is good but it can easily be made to point to wrong values.

For example if time shouldn''t exceed 24 and not be below 0 we can use constructors in C++ but we wil have to do a lot of error checking in c.
Overall C++ is better than C.

Regarding tight hardware - just use dos. In the world of openGL and 3dfx I don''t suppose tight hardware will exist - but if it does just use dos and break your head on doing 3d(pretty good way to learn though).






Share this post


Link to post
Share on other sites
(Object Oriented Design != C++) = TRUE

Yeah, people say that C++ is for OOD alot, but in fact, C++ was designed to be a multi-paradigm language. OOD is just one of many directions you can go with C++. The anonymous poster obviously knows a thing or two about programming to point this out.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

Object Oriented Design != C++


Er, no one ever said it was. The statement I believe you are referring to was that "C++ is object oriented" which is true and false. It has object oriented techniques built into the language but you aren''t forced to use them.

As for which language to use, both C and C++ are used in professional games, with C++ becoming more and more popular (although I believe C is still more widely used). I personally use C++ as I believe an object oriented approach makes more sense.


- Houdini

Share this post


Link to post
Share on other sites
For example if time shouldn''t exceed 24 and not be below 0 we can use constructors in C++
-----------------------------------

Huh? I really can''t see how much a constructor can help in that type of error checking as its only called once, when the object is created. Both languages really need error checking at the point of the problem. Regardless, both languages need alot of error checking, neither needing less.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro$haft BSOD T-Shirt

Share this post


Link to post
Share on other sites
quote:
Original post by ImmaGNUman

For example if time shouldn't exceed 24 and not be below 0 we can use constructors in C++
-----------------------------------

Huh? I really can't see how much a constructor can help in that type of error checking as its only called once, when the object is created. Both languages really need error checking at the point of the problem. Regardless, both languages need alot of error checking, neither needing less.

-----------------------------



ImmaGNUman, what he is saying is that in C++ you can put in range checking in your constructor and accessor functions. This way when you or the user changes the time the range checking is done automatically and you never have to worry about explicitly calling it.

In C you'd normally have to do range checking manually anytime you change a variable in your time structure.

Of course you could emulate what C++ does by creating a function where you pass a pointer to the structure and the new value, but that begs the question of, "Why not just use C++".


- Houdini


Edited by - Houdini on January 15, 2001 1:46:23 PM

Share this post


Link to post
Share on other sites
Oh man, why do we always have to ask this question??

Personally, I mix C and C++... I make extensive use of classes in almost all my programs, but that's just about all the C++ I use... all the code for the functions are pure C

For instance, I almost NEVER use cin and cout and fstream and iostream and << and >> and the other C++ stuff... instead, I use the *printf and *scanf and for file i/o, I use C's fopen(), fread() and all that....

Also, I find myself using less and less of struct's ...

So to sum up... C++ classes give my programs a frame work, a skeleton, if you will.... all the meat of the program, meaning the code in the functions, is pure ANSI C.

my $.02 * 10

Edited by - somecodeguy on January 15, 2001 3:37:59 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Personally I hate printf and scanf! In CKonsole-programms I only use cout and cin. I think they are much more comfortable and customizable.
I also love STL (Standart Template Library). I use it in all my programs which are not time critical. And even if so, STL is often a got choice.
My code is always a mix of classes, global variables and functions doing a lot of helpfull(?) stuff...
Danvil

PS:
( Object Orientated Designe != C++ ) == true
and not ...=true

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hmm........
if( (Object Oriented Design != C++) == true ) cout << "Right" << endl;
else cout << "False" << endl;

LOL

Share this post


Link to post
Share on other sites
Just pointing out something (yes, I''m pedantic):

smarson wrote:

(Object Oriented Design != C++) = TRUE

when in fact it should have been

(Object Oriented Design != C++) == TRUE;

You should be very careful when using = (assignment) and == (equality)!

:-) Enjoy!

Simon Wilson,
XEOS Digital Development

Share this post


Link to post
Share on other sites
(C++ & Object Oriented Design) == true;

Oh, and if we''re discussing C++, don''t use BOOL/TRUE/FALSE. Those are horrible C macros. C++ has a built-in bool type.

(You''d think most programmers would quickly realize these things, but this topic proves otherwise)

Share this post


Link to post
Share on other sites
Oh what the heck. If you can''t beat them, join them.

It should be
(C++ != ObjectOrientedDesign) == true;

or (C++ != Object_Oriented_Design) == true;

Object Oriented Design isn''t a valid variable name. You can''t have spaces in a variable name

Share this post


Link to post
Share on other sites
quote:
Original post by jonnyfish

Oh, and if we''re discussing C++, don''t use BOOL/TRUE/FALSE. Those are horrible C macros. C++ has a built-in bool type.

(You''d think most programmers would quickly realize these things, but this topic proves otherwise)


Actually, I disagree. If you look at how Microsoft implemented the BOOL macro you''ll see it''s typedef''d as an integer. As you know using 4 byte variables are slightly faster than using a 1 byte variables in 32bit operating systems because of memory alignment. So if you want speed, you leave the typedef as a 4 byte variable. If you want to conserve memory (ie, your porting to a handheld device) you change it to a char. Each change takes 1 line of code.


- Houdini

Share this post


Link to post
Share on other sites
Yes, but if you were compiling for hand held, wouln''t int be changed to the standard bit width of the hand held device, which would probably be smaller and also the devices fastest?

Anyways, if you were trying to save space, you would probably go for sticking 32 (or 16 or whatever) bools into the one int?


ANDREW RUSSELL STUDIOS

Share this post


Link to post
Share on other sites
Or stick 8 into an unsigned char (hey, if you only need 7 bools, only one bit would be unused). Seriously, though, if you''re so worried about speed and memory usage, why are you even using a high level language? Can I see some of your 64k intros, Mr. l33t hax0r?

Share this post


Link to post
Share on other sites
"l33tness" varies in different groups of people. The Quake crowd usually use "1337", while the Half-Life crowd usually prefer "l33t". The version I use depends on which game I''ve played last.

Share this post


Link to post
Share on other sites
quote:
Original post by jonnyfish

Or stick 8 into an unsigned char (hey, if you only need 7 bools, only one bit would be unused). Seriously, though, if you're so worried about speed and memory usage, why are you even using a high level language? Can I see some of your 64k intros, Mr. l33t hax0r?


Sigh, apparently you totally missed my point jonnyfish. BOOL and such macros are NOT horrible macros, there are definate uses for them, whether you want to believe it or not.

Yes, you can stick 8 into a char, but that would require major changes to the code. You can't do that with one line of code, thus your code isn't near as portable as using a BOOL macro.

And for you information I've had to port apps over to Windows CE where memory IS at a premium and that macro was an EASY way to keep my memory usage down to a minimum.


- Houdini

Edited by - Houdini on January 23, 2001 12:36:08 AM

Share this post


Link to post
Share on other sites
quote:

Yes, you can stick 8 into a char, but that would require major changes to the code. You can''t do that with one line of code, thus your code isn''t near as portable as using a BOOL macro.



Yes I know this is way off topic, but could you do it like this (and I''m no hotshot on C++ either (ph33r the VBist)... so correct me when I''m wrong)

Assigning stuff:

ByteLongThing = ByteLongThing && (Assign << BoolIndex)

Retrieving stuff

Value = ByteLongThing && (Assign << BoolIndex)

Is that right? I always like to see how my C++ery is coming along But yes it is ugly isn''t it =)

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites

This topic is 2576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.

  • Advertisement