Sign in to follow this  
sunsflower

Is making game with c possible?

Recommended Posts

TL;DR; of the abvove posts:

 

The advantage of C++ is more options to structure your code in readable ways, while not really having any disadvantages over C.

 

So the question is more "why use C?", which it seems like more and more people answer "there is no reason", so they use C++.

Edited by Olof Hedman

Share this post


Link to post
Share on other sites

or have you cake and eat it too.

 

i use a c++ compiler for the stronger compile time checking, but the code is largely C.  if i want to use C++ syntax i can.  if i don't, i don't have to.   so if i need polymorphism, inheritance, lambdas, etc, they are available. but 99% of the time, plain old C without the sugar coated wrapper of C++ syntax works just fine, and is usually less typing.

 

in general when you ask this type of question you'll get two types of responses, those from folks who only know c++ (younger programmers), and those who know there were games before C++ existed (older programmers).

 

i wrote my first PC game in 1982. so i'm definitely in the "games came before c++" group. 99% of the original purpose of c++ syntax was to make extending existing code bases easier.  unfortunately, extending exiting code bases is something that's rarely required in games.  but of course, if you've got a new hammer, you've just got to frickin' use it.  so wait!  we can also use it as a design methodoloy!  but again, unfortunately non-trivial games are about performance, not academic design methodologies / methods of source code organization.  those raised on C++ alone are usually unaware of the original purpose behind c++ syntax, and the history of the rise of OO design methodology.

 

this also speaks to the continual trend of hardware and software manufacturers coming out with new stuff (other than graphics cards), but not directly targeting games. and then feeling left out, gamedevs try to find a way to use the new tech. or non-gamedevs espouse the tech as a game solution (anyone remember MMX instructions?). in many such cases the fit between games and tech is forced or kludged or only works up to a certain point.  

Share this post


Link to post
Share on other sites

I use C quite a bit, personally. It doesn't really provide much benefit over C++. I like it because not having classes handy can push me to think about different ways to design code. I don't think I've figured out anything novel yet, though. There's only two reasons why I would recommend anyone else use C over C++:

1) You don't want to, or can't, link to the normal libraries.
2) You're considering working with a C purist.

The second reason might come up in game development. There are some C purists in the hobbyist crowd. Usually their reasons for being C purists are pretty pointless, but in my experience they're usually crazy good and worth working with just to learn a thing or two.

The first reason is not likely to come up in game development *anymore*. Even cheap low end computers have enough hard drive space and memory to make saving 1-2mb fairly pointless (this was not the case 15 years ago).

The first reason *might* come up if you're doing other sorts of programming. For example, the C runtime isn't available in an OS kernel, or on a custom OS. The C runtime might not be available in certain embedded environments. If you're writing web services using CGI (common gateway interface), cutting out some of the pre-main work might be worth it.

Like Norman, a lot of my code winds up looking like C code even when I'm programming in C++. The "C way" of doing things is usually (but not always) more efficient, but you can always do the "C way" in C++, and still get all the advantages of C++.

Edited by nfries88

Share this post


Link to post
Share on other sites

To play Devil's advocate, OOP isn't loved by everyone.

 

https://www.youtube.com/watch?v=IRTfhkiAqPw

 

A lot of people think it is terrible.  They will say don't use C++ because it has objects.  But, as pointed out above, you can write C++ and not abuse OOP.

You need tons of games to find your style and figure out if it saves you time and energy and money, or it doesn't.

 

Don't worry about it.  Go write games.

Share this post


Link to post
Share on other sites

A great book to read, old now but what it says is still valid and will teach you a huge amount about what and why in C++ "The design and evolution of C++" by the creator of the language. It goes into the choices that were made, why they were made and give you insights into the core language that will deepen your understanding of the language. The deeper your understanding the better you can use a language and back in the day this gave me insight that no other books gave.

Share this post


Link to post
Share on other sites

why we always use c++?

We don't. I personally use C++, C#, JS, Ruby, Java( Joke, who the hell uses this?), some python, and some more.

The variety is huge when talking abouty tools today. You can use whatever you feel comfortable with.

You can even experiment with new tools and languages. (Recommended)

 

what is the advantanges of c++ over c in game development?

The ++.

It has far more features which in generally make you more productive.

You don't need to reimplement code that has been reimplemented over million times.

Although low level api is still in C, you could take advantage over the high level api that is in the market to make a game faster.

Don't be a hipster, there is a reason C++ is an industrial standard, I advise you to read on your own and learn what C++ is capable of.

 

and does making game with c makes sense at all?

Yes. Mainly with low level api such as OpenGL. 

C was always there, it is not considered hard but it is not easy either. 

You need to stick both legs in the mud and shove a spoon inside your mouth, but it is possible. 

Share this post


Link to post
Share on other sites

The modern pseudo-argument in favor of C is that its "more transparent" -- namespaces, and classes, and templates, and operator overloading, and virtual member functions, and overload resolution taking all of those into account, and lambdas, and exceptions, and rules of 5 and 3 and 1, and on-and-on are all compiler voodoo that some believe is too opaque to be trusted -- or, at the very least, that it short-circuits critical thinking regarding platform-level details, and sometimes that this allows lesser-skilled programmers ("undesirables") to sneak in and wreak havoc in places they are not welcome. This is the basic position that Linus Torvalds takes with Linux kernel development (unapologetically, as is his custom) -- though, there are good reasons for not wanting a mix of C and C++ in the kernel, and C is already entrenched for historical reasons.

 

But I don't consider that a good reason, for or against, myself. Many patterns that C++ makes easy are useful (e.g. classes, virtual member functions) in C, and can be replicated to a reasonable degree with some work -- for example, a virtual member function in C++ is basically a function pointer with a convenient syntax for declaring, defining, and calling them. C code that does this sort of thing looks different, but you can find examples of it in the Linux kernel, in Quake, and in Halo's engine.

 

C++ is generally more convenient and productive than C, IMHO, but there is some truth to the argument that the compiler does things behind your back, and its true that this can in some cases cause trouble. But its not terribly difficult to learn where most of the dragons are, and to guide yourself to a comfortable subset of C++ and way of speaking it that avoids them.

Share this post


Link to post
Share on other sites

There is no need to use c++ for making games. You can make games in plain C as well - just using structs and unions.

But there are a few features from the c++ compiler which makes life much easier - operator overloading and zero struct initialization. Thats it.

 

"That's it -- operator overloading and struct initialization are the only things that make life easier in C++"? Or, "that's it -- you can mostly do everything in C that you can do in C++, but C++ is often a more convenient language"?

 

The former falls far short, the latter is a reasonable approximation. I would encourage today that there's no good reason to avoid C++ in favor of C, unless you are not in control of all the reasons you have to deal with -- you have no choice if C++ is unavailable or impractical for the obscure micro-controller you're programming. You have no choice if your boss says "We speak C here" or if you're hacking on the Linux Kernel. You have no choice if this is CS 110: Introduction to C. But if you're in control of the reasons and the thinking surrounding them, then there's precious-little reason to choose C other than simple, personal preference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this