Archived

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

Russell

Any reason to use C?

Recommended Posts

If you don''t know why you would want to use C, you don''t need to use C. It is, however, useful to know.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
I can think of reasons why someone might want to. Maybe they like to be able to actually read the assembly source code generated by the compiler. C++ mangles names due to function overloading, or some such.

I''m not looking for answers for myself personally. I would like to know what reasons people might like to use C instead of C++ nowadays. So rather than saying, "if you don''t know don''t worry about it", I''d like to know what YOU think.

Share this post


Link to post
Share on other sites
Embedded systems programming is a biggie, as is low-level operating system programming. Also, when making a library that may be used by people using C (for whatever reason), it''s often a good idea to write it in C.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
One could also write the library in C++ with the functions exposed using C linkage.. :-)

No seriously its just personal preference. C is a cleaner language with fewer constructs than C++ and has a certain beauty to it. Also a serious concern with C++ is that though it has a standard compiler makers are not that great in implementing it to the letter.

This might not seem like a big issue but when you have a multiplatform game with 100 000 lines of code and twelve programmers those subtle differences become increasingly more of a pain to handle. And you bet they pop up before the milestone build, personal experience talking here!!

But, for one or two persons working on a hobby/freeware/shareware game those resons are not an issue. Use the language you''re most comfortable with. I would suggest C++ but thats just _my_ preference.

Unless youre on a gba... c++ on a gba is totally overkill in my humble opinion.

Per Dervall
Programmer
Warthog Sweden

Share this post


Link to post
Share on other sites
quote:

One could also write the library in C++ with the functions exposed using C linkage.. :-)



exactly what I''m doing to link OCaml to a Direct3D engine hehe.

I tend to think of C as cleaner, but for a large project C++ has more nice constructs for segregating implementation and interface. Although C++ is supported on most platforms anyway, I still (it''s mostly an illusion I know) see C as being more portable.

Share this post


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

One could also write the library in C++ with the functions exposed using C linkage.. :-)



exactly what I''m doing to link OCaml to a Direct3D engine hehe.



O''Caml???!?!?!?! Please, tell me you''re joking...

But why would you want to learn C? Well, if you''d like to become an anachronism... j/k. Good for low level stuff, OS''s, etc. Not cleaner than C++ if you know what you''re doing. But you have to do a few more things, like putting the word "struct" whenever you use a struct variable in your program, etc. C++ cleaned a lot of that kind of stuff up.

-Nick

Share this post


Link to post
Share on other sites
quote:
Original post by nickwinters O''Caml???!?!?!?! Please, tell me you''re joking...
I remember when I was young and stupid. I laughed at anyone who said they used LISP. How foolish I was...

So, what''s wrong with OCaml? Have you ever used it for anything significant? It is as about as fast, or faster, than C or C++ for quite a lot of things.

In general, functional languages are about as fast as C/C++ nowadays, and they make a lot of things easier on the programmer.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
all of my new hobbyist Windows stuff is OOP-style C++, or more recently templated classes. but all of my old Windows stuff and all of the Unix stuff i get paid for now is in ANSI C, even the new code (mostly embedded SQL related.) but most of that''s just because i''m very comfortable with the coding style i use for that language. i could just as easily use some of the C++ functional extensions if i didn''t want to do OOP style C++ though, but i don''t. it''s just force of habit i guess.

if C were to die today i wouldn''t miss it since I still could create "terse" code using C++. and to me that''s always been one of the strengths of C. but i know times change so i''m slowly changing with them.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
and knowing C might just land you a job in this tight job market, whereas only knowing C++ might not. i know it''s not likely these days but what if all you knew was STL instead of STL and stdio and stdlib and ...? it could potentially make the difference between you and a competitor, assuming you would want the job in the first place. i know some highly paid people who do nothing but support legacy code written in COBOL, RPG, C, FORTRAN, MUMPS, etc. and when it comes time to migrate the code to a newer language they get free training to boot. assuming they just don''t out source the work off shore instead.

i think it''s much like knowing Latin. might not get you anywhere, and you more than likely will never use it, but it looks good on a CV/resume.

Share this post


Link to post
Share on other sites
I personally still use some aspects of C when coding, even though I''m doing OO C++ for the most part. Formatting strings is one big example--I know that you can, eventually, mangle strstream into formatting appropriately, but sprintf will do it in one line of code. I don''t know of an equivalent to strncpy, though I''m sure I could kludge one together. Same with most of the other strn* functions.

Of course, if I''m just mangling strings, I much prefer perl--with its regular expressions, . and + operators, strings are very easy to play with. But that''s beside the point.

-Odd the Hermit

Share this post


Link to post
Share on other sites
Majority of windows apps use MFC thus use C++. D3D can be used within C and win32 but I don''t recommend it. Even embedded world is using C++ nowdays because processors got cheaper and faster and appliances got more complex. Actually, the world is moving towards Java/.net and away from C++ for most apps. Games are niche markets where C++ is used more so than other langs. One thing is certain and that OOP is going to be in future langs. I hear C# will get updated with C++ feature set down the road. I think Java also will get templates.

Share this post


Link to post
Share on other sites
quote:
Actually, the world is moving towards Java...
Oh god no...I like OOP to a certain degree, and then some of the things just become major overkill for 99% of things that need to be done. I think Python would be a much better place to move towards than Java.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i''m always curious where these guys who make such definitive statements in their posts get their info from. JD, could you please site some sources of reference to back up your assertions? especially this one: "Actually, the world is moving towards Java/.net and away from C++ for most apps." where did you read this? was it on-line or in writing? perhaps in a peer-reviewed periodical? were there statistics shown along with the statement? was this a global sampling? how large was the sample? any other statistical info would be helpful.

there''s several other in there i would like links/references for as well, if you wouldn''t mind? thanks.

Share this post


Link to post
Share on other sites
there''s a difference between using C, and using C paradigms.

nothings wrong in using c-style features, like functions, and such, in c++ as well. you can use it there, unlike in java for example. so use your c programming knowledge where it suits your needs..

but on any platform with a decent c++ compiler there is no reason to use C as language. C++ can do what C does with minor differences, and can add a lot of other features, too.

there is no reason to use C as programming language anymore, except because it''s the only language of choise, or legacy support of a c programmed product.

there IS reason to use what you learned in C to program with that knowledge in C++, too. you can still use structs, you can till use functions. so use''em where they''re useful

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
quote:

Original post by nickwinters
O''Caml???!?!?!?! Please, tell me you''re joking...



Ahahaahahaa yes. I. am. joking.

No, OCaml certainly has it''s issues, this project is very much a ''proof of concept'' but based on some other work, I''m convinced it will (or at least can) work well. I''m happy to sacrifice a slight performance decrease in certain sections (and the actual renderer/engine code divide isn''t fixed yet) for benefits including type inference, serious polymorphism, reduced development time etc. In fact, the biggest headaches I''ve currently got are:

i) making sure the GC doesn''t start getting in the way
ii) how to integrate Lua without amassing an enormous C->OCaml->C->Lua->C->... sequence although I''m sure most of it can be generated anyway.

I''d have been happier if you''d asked me if I was joking in using Direct3D

Share this post


Link to post
Share on other sites