Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

I got a couple of questions based on Old C programming.


zeph77
 Share

Recommended Posts

Hey everyone, this time I got a couple of questions upon the C programming language. At the moment I am learning C# which I find to be pretty easy in terms of actually simplifying some stuff but I had a few questions on C this time.

First, In C programming memory is managed with the malloc() function but what if somehow an error occurs when you try to allocate memory for something? Wouldn't that cause a leak or is there a way to avoid such a problem? I know in C++ they added the smart pointers to help with C++ memory allocation but I was wondering on C. Probably not the best description but I read somewhere that leaks can happen in a similar way.

Second, Isn't it possible to apply Object Oriented principles to C as well? i'm starting to see a lot of people as of this year and idk about next changing back to C. I guess it could be the challenge of using such principles in C but since you can why don't people actually make games with C?

Third, Compared to the other languages, is C more easier to port or can it just run on different operating systems? I know windows and linux can but things like ios, android, ect…

Even though C# is really nice, has cool features and just makes things more simpler I just think C is important and its not to huge to actually learn either just the memory management and lists take up most of the time to learn for me.

So Im trying to get good at both worlds but like I said my main focus is just making software someday, game development(mostly 2d side scrollers, arpgs, rts) I don't want to touch on 3d anytime soon. Also even making tools since C# seems to be good at that. Thanks for any reply's and I'm trying to practice 2 hours - 4 hours a day in this.
Link to comment
Share on other sites

Myself and a few others honestly have no idea what you're asking or what type of information you're looking for. You sort of went all over the place in your post. If you're wanting to find out the pitfalls of C memory management I'd suggest heading on over to a more authoritative forum on the subject (stackoverflow.com comes to mind) where you can get answers from multiple people from different angles. The same thing applies to your question about object-oriented programming in C. I know that there is something called "Objective C" but I haven't dabbled in it myself.

I can answer your subjective question regarding porting quite easily with a subjective answer: There are a variety of tools that can be used with any language to allow for cross-platform operation, including but not limited to C#.

"Why don't people use C to write games?" Because it's procedural and it's very low level in terms of how close it is to the machine. It's generally used to write system components that communicate directly with system hardware and other devices; you'd more or less use C if you wanted to limit resource usage on an extreme level (at least that's what I've garnered from the reading I've done on it, and having learn the basics of it a few weeks ago). When you said, "C# actually simplifies some stuff" you hit the nail on the head and answered your own question. Game developers want to spend more time writing code that does something rather than writing code that allows other code to do something.

Last but not least, if you wish to get into game development at some point I'd highly suggest going to school for it; you'll get a lot more out of it. If school isn't an option make a choice. C/C++ or C#. Once you've made that choice, stick with it; study it; master it. Once you've done that you're free to do anything with any other C derivative out there as long as you don't lose your aptitude to learn syntax and implementation.
Link to comment
Share on other sites

Thanks and I have been dedicating most of my free time learning C# atm through some video tutorials and some tutorial written out from a book just more simplified. I might just get a book when I have enough money or just keep searching online and I just think learning in college would be a waste of money since it seems a lot of resources are online now and I just finished a web design class that yeah.. it taught web design but hardly touched on html and css(I already knew html/css at the time) which made my teamates feel like they weren't learning everything and thats why I brush college off, If I do get a degree it won't guarantee me a job. Its just I always wondered about making things with C but I guess its hardly done anymore and mostly used for engines and like you said, hardware.

I actually do have 2 questions though about C#. Can you make a great engine with C# without the fact that people consider C/C++?

Also when learning C# is it better to mess with the console (i did this with C++ before I got into the UI stuff) or both console and windows forms?

Not that I would even try to attempt to make an engine in the future since there might be some out there but just a thought since people say it wouldn't be as great. I guess I'm just a bit paranoid as to if I learn a certain language would it be a waste of time learning it or would it stand out.

Anyways thanks for the reply and sorry for the random questions.
Link to comment
Share on other sites

> Thanks and I have been dedicating most of my free time learning C# atm through some video tutorials and some tutorial written out from a book just more simplified. I might just get a book when I have enough money or just keep searching online and I just think learning in college would be a waste of money since it seems a lot of resources are online now and I just finished a web design class that yeah.. it taught web design but hardly touched on html and css(I already knew html/css at the time) which made my teamates feel like they weren't learning everything and thats why I brush college off, If I do get a degree it won't guarantee me a job. Its just I always wondered about making things with C but I guess its hardly done anymore and mostly used for engines and like you said, hardware.
>
> I actually do have 2 questions though about C#. Can you make a great engine with C# without the fact that people consider C/C++?
>
> Also when learning C# is it better to mess with the console (i did this with C++ before I got into the UI stuff) or both console and windows forms?
>
> Not that I would even try to attempt to make an engine in the future since there might be some out there but just a thought since people say it wouldn't be as great. I guess I'm just a bit paranoid as to if I learn a certain language would it be a waste of time learning it or would it stand out.
>
> Anyways thanks for the reply and sorry for the random questions.

Once again you're all over the place with questions. A computer science degree will put you WAY ahead in terms of credentials for your resume than if you "brushed it off" and went the self-taught way. You can practically do anything with C# that you can do in C++; the only thing that changes is the availability and access of intermediate libraries. For C#, you have SharpDX, SlimDX, and XNA. I personally use XNA, and it is 100% legitimate in terms of using it for independent development.

C/C++ and C# are the primary languages used by professional game studios. You can't go wrong with learning any of them. The key is to simply learn programming (not a language) from the ground up and apply what you know to a specific language or an array of languages. It takes years to become very fluent in any language just because there are so many specializations that, in their own right, require months if not years of study.

Stick to my philosophy and you won't go wrong: Choose, learn, put into practice.
Link to comment
Share on other sites

Alright thanks and ill do my best. I'm still in college but the thing that makes me angry is they want me to take math courses for the CS degree and they told me they don't have all the courses so I have to transfer or some crap. Also I heard the programming classes sometimes get canceled because people think its too hard and they drop out. A lot of programmers told me that math isn't a very big thing and by math I mean stuff like linear algebra, calculus and the like. I'm not too sure if I plan to do any 3d stuff so thats why I think its lame. Mostly in games I see people just add, subtract, multiply or just divide things.

I'm thinking of just getting a good book on C#, sitting down a few hours and just reading it while taking notes just like I would in a classroom. In college i'm just leaning toward the web development side side of things since I want to become a web developer but I like programming so I want to do it as a side thing and freely. Right now I just got html(some of 5)and css(some of css3) remembered and just a bit of javascript. C# seems to be able to do some web stuff too so I guess its a plus.
Link to comment
Share on other sites

> Alright thanks and ill do my best. I'm still in college but the thing that makes me angry is they want me to take math courses for the CS degree and they told me they don't have all the courses so I have to transfer or some crap. Also I heard the programming classes sometimes get canceled because people think its too hard and they drop out. A lot of programmers told me that math isn't a very big thing and by math I mean stuff like linear algebra, calculus and the like. I'm not too sure if I plan to do any 3d stuff so thats why I think its lame. Mostly in games I see people just add, subtract, multiply or just divide things.
>
> I'm thinking of just getting a good book on C#, sitting down a few hours and just reading it while taking notes just like I would in a classroom. In college i'm just leaning toward the web development side side of things since I want to become a web developer but I like programming so I want to do it as a side thing and freely. Right now I just got html(some of 5)and css(some of css3) remembered and just a bit of javascript. C# seems to be able to do some web stuff too so I guess its a plus.

"C# seems to be able to do some web stuff too." Just **some**? Say hello to [http://www.orchardproject.net/](http://www.orchardproject.net/); it's an ASP.NET CMS written entirely in C# (back-end, obviously). And bro, you either have some serious misconceptions about what game programming is or you've been lingering around people who have no idea what they're doing for too long.

Those math courses are entirely necessary if you ever want to break into the industry or even do it as a hobby without banging your head against a wall, and I wish my math was as good as I'd like it to be for just that reason. Too many times have I wanted to do something and I've been stuck because my math isn't up to par, and that's only in 2D. There are tons of uses for linear algebra in 2D game development, including rotation, scaling, trajectory (moving objects in other than a straight line requires more than just simple arithmetic), the list goes on.

If you're just wanting to do game development as a hobby then I wouldn't get involved with CS; you probably wouldn't be interested and it sounds like you're turned off by what it (CS and game programming) requires. Since you're in college I think you'd be interested in visiting www.dreamspark.com and www.pluralsight.com. DreamSpark memberships include a free 90 day trial of pluralsight, and pluralsight is a great way to learn just about anything you want to know about any language. DreamSpark also provides you with Visual Studio 2010, 2012, and some other cool stuff (Expression Studio 4 Ultimate, includes Web, Blend, and other things you might use for web development).
Link to comment
Share on other sites

> "C# seems to be able to do some web stuff too." Just **some**? Say hello to [http://www.orchardproject.net/](http://www.orchardproject.net/); it's an ASP.NET CMS written entirely in C# (back-end, obviously). And bro, you either have some serious misconceptions about what game programming is or you've been lingering around people who have no idea what they're doing for too long.
>
> Those math courses are entirely necessary if you ever want to break into the industry or even do it as a hobby without banging your head against a wall, and I wish my math was as good as I'd like it to be for just that reason. Too many times have I wanted to do something and I've been stuck because my math isn't up to par, and that's only in 2D. There are tons of uses for linear algebra in 2D game development, including rotation, scaling, trajectory (moving objects in other than a straight line requires more than just simple arithmetic), the list goes on.
>
> If you're just wanting to do game development as a hobby then I wouldn't get involved with CS; you probably wouldn't be interested and it sounds like you're turned off by what it (CS and game programming) requires. Since you're in college I think you'd be interested in visiting www.dreamspark.com and www.pluralsight.com. DreamSpark memberships include a free 90 day trial of pluralsight, and pluralsight is a great way to learn just about anything you want to know about any language. DreamSpark also provides you with Visual Studio 2010, 2012, and some other cool stuff (Expression Studio 4 Ultimate, includes Web, Blend, and other things you might use for web development).

Thanks and yeah idk if I would do actual computer programming as a job since its really hard to get in anyways from every programmer I talked to in the industry told me. I went to an interview just for a junior position to get some training at least and they said they don't mind training but they did VB.NET mostly and only some C# which I didn't know how the syntax worked. I did mess up on this opportunity because some things I said(I acted like a bad ass..) and thats why I didn't get it. They wanted a senior anyways. I will def. check the websites out and see whats up, web development seems fun and I mostly like to deal with making UI's and just anything 2d at least for now. I'm enrolled in a math course also at the moment but I was moved way back to arithmetic so I have to start over again which is fine. My goal is to make my dream game of a 2d action rpg(fast paced but not too fast). I would love to learn how to make it online but thats another thing that I hope a good book on C# would cover. For now I think ill just read the book you suggested. Thanks for the help and have a good day sir.
Link to comment
Share on other sites

> First, In C programming memory is managed with the malloc() function but what if somehow an error occurs when you try to allocate memory for something?

It depends on the operating system your programme is running on. Generally, if malloc fails, it will return NULL, which is an indication that libc was unable to allocate sufficient memory. However, most operating systems, will simply swap away pages from memory to a storage device, in order to allocate more space, until there is no swap space left, in which case the operating system will start killing processes.

> I know in C++ they added the smart pointers to help with C++ memory allocation but I was wondering on C.

Smart pointers are a concept that is entirely based on exploiting the rather implicit behaviour of C++. Since pointers themselves are allocated on the stack, some C++ programmers decided to implement an actual class for pointers, where the destructor is used to check if the memory that is being pointed to, is still being referenced to by other pointers. In case the pointer of which the destructor is called, is the last pointer to reference that memory region, it will free that memory region automagically. That way, since the destructor will be called when the pointer is freed, which happens at the end of scope, the memory you have allocated will be freed for you.

> Second, Isn't it possible to apply Object Oriented principles to C as well? i'm starting to see a lot of people as of this year and idk about next changing back to C. I guess it could be the challenge of using such principles in C?

Writing object-oriented C code is as simple as using structures, and functions that generally operate on those structures. The major difference being that the syntax is a bit more explicit than for actual object-oriented programming languages. More advanced concepts can be implemented as well, such as inheritance and virtual or overridable functions, through typecasting and function pointers, respectively. However, most of the more advanced concepts are avoided outside libraries.

> why don't people actually make games with C?

There are actually quite a few games that have been written in C. However, as C++ supports most of the features that C has to offer, and as C++ is more implicit, it is often used instead. Albeit, not for libraries, because C++ isn't as portable as C.

> Third, Compared to the other languages, is C more easier to port or can it just run on different operating systems? I know windows and linux can but things like ios, android, ect…

Applicatons programmed in C can be ported to just about every operating system (noticeable exceptions being operating systems that run virtual machines, and do not allow native code to be executed, such as Windows Mobile 7).

Yours faithfully,

S.J.R. van Schaik.
Link to comment
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
 Share

×
×
  • Create New...