Sign in to follow this  
yurian

Is C obsolete?

Recommended Posts

I would think that a lot of OS and driver development still uses C (rather than C++). And, back in the Visual Studio 6 days, all Microsoft IDEs and Office products were developed using C (and straight Win32). That may have changed.

C is also still used in the low speed CPU world (PIC, 8051, z-80, etc.)

Share this post


Link to post
Share on other sites
I use C all the time for microcontrollers and also for some of the stuff I do with robotics. Many of the microcontroller and robotics folks are working on going to C++ but just like everything else it takes time.

theTroll

Share this post


Link to post
Share on other sites
Like TheTroll mentioned, lots of embedded systems end up requiring you to use C. There's a simple reason for this. C has been around for well...a long time now -- because of this, it's been ported to a bajillion architectures. When you make a new kind of processor architecture, or even a complicated microcontroller...and you plan on letting people write programs for it; you have to give them some way to write programs that removes the need to speak processor language (can you imagine having to write in x86 machine code? ugh...).

C, because it's been around a while, because lots of people are familiar with it, and because its standards are more or less fixed -- is a decent choice for a language to implement a compiler for. I'm not saying writing a compiler for C is -easy- (for from it...), but because so many people have done it before, it makes things a -bit- easier :)

~Shiny

p.s. Lots of people are trying to move things to C++ -- I have worked on embedded systems that use C++ lately, unfortunately because someone had to make their own implementation of standard library stuff for this particular hardware -- sometimes the standard library stuff does not work as expected :'(

Share this post


Link to post
Share on other sites
No language is ever really "obsolete". The platform it runs on can become obsolete, but that's different.

C runs on virtually everything. Unix and Linux were written almost purely in C. A lot of robotics and embedded solutions run C.

I don't like C++. It has a lot of things I don't want/need, and there's not really anything it can do that C can't.

Not to mention, a C compiler exists for pretty much every operating system out there... The same can't be said for a lot of other languages.

Share this post


Link to post
Share on other sites
Quote:
Oh, I forgot to mention, a properly programmed C program is FAST.

Sorry to rebuke but this comment stuck out at me.

A properly programmed C program does the same thing any properly programmed software does in any language... perform a task to spec.

Share this post


Link to post
Share on other sites
All of the reasons stated so far are valid, but I'm always surprised in these threads that one particular item never seems to come up, yet for me it is THE reason why C is still not only used but of vast importance to the development community:

Binary compatibility.

Standard compliant C compilers are required to output their structures and function entry points into the final binary a certain way, and no one really deviates from it. What this means, practically, is that I can take a C library compiled with a Microsoft compiler (like the Win32 lib) and call it's functions and use its structures from, say, a compiler from GCC or Borland or Intel or anywhere and KNOW that it will work. You simply CANNOT do that with today's C++ compilers. Heck, even different versions of the same C++ compiler may be binary-incompatible.

This is why a great many plugin setups (Maya comes to mind, but there are many, MANY others) are in C, as are a great many standard libraries like OpenGL, as well as why most tutorials on DLL usage have you wrap everything exposed to the outside world in a "C" declaration. Everything can read it! Most other languages also include a method for calling C functions from a lib or DLL (Python, D, .NET, etc.) for the same reason. AND it's why COM is built around many many layers of awkward C code. Have I beat the dead horse enough yet, because I'll go on if I have to :)

Now C isn't the only language out there that does this. .NET actually has a nice setup for "binary" compatibility, but C has the advantages of cross-platform compatibility and native compilation (read: speed). Other languages that conform to a specific binary format usually have the simple disadvantage that they aren't as well known as C.

The list goes on and on, but what it all boils down to is that when interoperability and speed are an absolute must C is generally the way to go!

Share this post


Link to post
Share on other sites
Quote:
Original post by Tom9729
My point was that if you write a program in C, and then write one in Java, the one in C is going to run faster.


Except when it doesn't. 'Java is slow' is an urban legend.

Share this post


Link to post
Share on other sites
Quote:
Original post by yurian
Then the obvious noob question, why is there C++? (Agonized thinking face)


So you could play games?
C++ is nicer to develop in large groups of people than pure C.


@Java:
One place where Java loses is at the direct hardware access. Java simply cannot do SSE instructions/OpenGL 2.0/DirectX (efficiently).

Edit: and using >256MB of memory takes changing the virtual machine's settings.

Share this post


Link to post
Share on other sites
Also, at least in many communities with very old and vast code bases [linux], C is still extensively used because there are slight incompatibilities between C and C++ source files. C++ might be a functional superset of C, but the transition from C to C++ also added new tidbits like keywords which result in C source files being uncompilable on a C++ compiler.

On a similar note, C++ is a pain to parse, which is why compilers have just recently started to really implement a complete and current C++ specification. If you hang around these forums for a while [or any programming forum that caters to the C/C++ crowd], you'll see countless statements that let you know that people still think Dev-C++'s and VS6.0's 'C++' is the real deal, and it just isn't. The results in old code bases growing even bigger [because really, why would they bother shifting from a stable C implementation to a shaky and buggy C++ implementation], which means they become even harder to change, resulting in C sticking around.

Share this post


Link to post
Share on other sites
Quote:
Original post by yurian
Then the obvious noob question, why is there C++? (Agonized thinking face)


for the same reason people don't write their programs in 100% ASM or on punch cards: progress.

I also have to agree to some things said by previous posters, sometimes C++ is too much for what you need and C is the better tool. For example, I happen to find C more usefull for coding various daemons on Linux, I need those for the website I'm doing in php and tried doing them in C++ but found that most of my time was spent thinking about "oop design issues" instead of focusing on the small tasks the program has to do ;) And to use a C++ compiler to compile C code would be just silly so I ended up writing them in C.

Share this post


Link to post
Share on other sites
Also, in case the OP wasn't already aware of it -- OOP stands for object-oriented programming (or I suppose you might substitute 'paradigm' for the P part also!). All this means is that C++ has language facilities built in that allow users to organise their code in terms of 'objects' and the 'methods' that those objects are capable of doing. This is very useful sometimes, but othertimes can just be overkill -- hence why C++ does not force you to follow this paradigm :)

~Shiny

Share this post


Link to post
Share on other sites
Lol, C is just as easy to learn and understand as C++ (they teach you C before they teach you C++, that's when they introduce more features.) sometimes even better, but when it comes to a higher level C++ is sometimes better (classes and all, they weren't easy for me to implement in C, I know I could use structs, but to add functions to them needed pointers and it was hard for me to understand structs). It totally depends on the person using, and his capabilities, and what the end result is needed to be. And C is not obsolete, C is used wherever possible, I know a couple of people using C instead of C++ or C#, even with OpenGL, SDL, DirectX, you say and they use it.

Just think if you don't need whatever C++ offers, and you can use C, why would you use C++, and you can't compare it to a lot of languages, because they are used in a very different way. Anyway, if I didn't need functions in structs, I would have never used C++, and even then I use the rest of the code from C. As someone already said languages never get obsolete.

You can't code in C++ without using C, and most C compilers work just as well with C++, I haven't seen C only compilers yet.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tojiro67445
This is why a great many plugin setups (Maya comes to mind, but there are many, MANY others) are in C,

That's incorrect. The Maya API, and the vast majority of application plugin systems (3DS Max, Cinema4D, AutoCAD's ObjectARX, etc) are all pure object oriented C++.

Often, not even the old extern "C" type interface is used anymore, but direct abstract inheritence into the plugin DLL.

Share this post


Link to post
Share on other sites
Quote:
Original post by Yann L
That's incorrect. The Maya API, and the vast majority of application plugin systems (3DS Max, Cinema4D, AutoCAD's ObjectARX, etc) are all pure object oriented C++.

Often, not even the old extern "C" type interface is used anymore, but direct abstract inheritence into the plugin DLL.


Really? Admittedly I haven't used the Maya API for a while (since before the merged with Autodesk) but I was fairly certain that back then it was a C API. Wouldn't surprise me if they've changed it since, but then it begs the question: How do they deal with the incompatibilities I mentioned previously?

Share this post


Link to post
Share on other sites
Quote:
Original post by Tojiro67445
Standard compliant C compilers are required to output their structures and function entry points into the final binary a certain way, and no one really deviates from it.

This isn't true. In fact, the same compiler with different compiler flags can emit function prologues and epilogues differently or have different structure formats. For example, unless you're careful to fully specify calling conventions on all function declarations, compile two C modules with MSVC, one with /Gd and one with /Gr and chances are if you link them together the resulting executable will implode.

Quote:
What this means, practically, is that I can take a C library compiled with a Microsoft compiler (like the Win32 lib) and call it's functions and use its structures from, say, a compiler from GCC or Borland or Intel or anywhere and KNOW that it will work.

What happens is that there is a set of calling conventions and structure layout descriptions that MSVC, Borland, ICC, GCC, etc. conform to on the Windows platform. And another set that Metrowerks and GCC conform to on the Mac platform, and so on. These are generally de facto standards set up by the OS developer.

Quote:
You simply CANNOT do that with today's C++ compilers. Heck, even different versions of the same C++ compiler may be binary-incompatible.

Much in the same way as the OS developer may specify calling conventions for use on the platform, there may be de facto virtual table layout information for the platform. On Windows, there is such a standard due to all major C++ vendors choosing to allow COM implementations with C++ object; COM being a binary standard that specifies vtable order.

Provided that shared interface information is restricted to COM types, two C++ compilers on Windows can generate interoperable binary code.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tom9729
No language is ever really "obsolete". The platform it runs on can become obsolete, but that's different.

ASP? Managed C++?

Quote:
Original post by Tom9729
I don't like C++. It has a lot of things I don't want/need,

So what? Does your program suffer from the fact that you don't use some feature? If C++ just has one feature you'll use then why not consider it? Of course since C++ was pretty much made by stapling arbitrary features onto C it is pretty complex, unpredictable and have quite a bit of "undefined behavior". This may make C++ harder to use, but it isn't worse just because it has more features, but because all these features affect each other.
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."

Quote:
Original post by Tom9729
Not to mention, a C compiler exists for pretty much every operating system out there... The same can't be said for a lot of other languages.

But it probably can be said for C++. It's true that some embedded system doesn't support C++, but has it ever been a problem for you? I bet it haven't for 95% of programmers. Sure if there is no C++ compiler you have no choice, but there almost always is.

Quote:
Original post by DrCoolSanta
Lol, C is just as easy to learn and understand as C++ (they teach you C before they teach you C++, that's when they introduce more features.)

Who do that? Most serious programming sites actually address this in their FAQ and tell that C should not necessarily be learned prior to C++ since they are different language that look superficially similar, but the coding style is usually very different. Bjarne Stroustrup (original author of C++) for instance answers this in his FAQ as,
Quote:
Q: Knowing C is a prerequisite for learning C++, right?
A: Wrong. The common subset of C and C++ is easier to learn than C. There will be less type errors to catch manually (the C++ type system is stricter and more expressive), fewer tricks to learn (C++ allows you to express more things without circumlocution), and better libraries available. The best initial subset of C++ to learn is not "all of C".

See Learning Standard C++ as a New Language for a discussion of the choice of C++ constructs, techniques, and libraries for early learning. For an example of a book that takes that approach systematically, see Koenig&Moo: "Accelerated C++" from Addison Wesley's C++ In Depth series.

At C++ FAQ lite they say,
Quote:
Q: Should I learn C before I learn OO/C++?
A: Don't bother.

If your ultimate goal is to learn OO/C++ and you don't already know C, reading books or taking courses in C will not only waste your time, but it will teach you a bunch of things that you'll explicitly have to un-learn when you finally get back on track and learn OO/C++ (e.g., malloc(), printf(), unnecessary use of switch statements, error-code exception handling, unnecessary use of #define macros, etc.).

If you want to learn OO/C++, learn OO/C++. Taking time out to learn C will waste your time and confuse you.


Quote:
Original post by DrCoolSanta
Just think if you don't need whatever C++ offers, and you can use C, why would you use C++, and you can't compare it to a lot of languages, because they are used in a very different way. Anyway, if I didn't need functions in structs, I would have never used C++, and even then I use the rest of the code from C. As someone already said languages never get obsolete.

C++ isn't about adding functions to structs. Such a tiny change could easily be done by writing a simple extension of the standard preprocessor instead of a completely new language. C++ is about getting type-safety, the ability to use modern abstractions, the ability to choose your own paradigm and the ability to use a standard library. If you don't want to program in a procedural way then C would be a bad choice. If you want type-safety C would be a bad choice.

Quote:
Original post by DrCoolSanta
You can't code in C++ without using C, and most C compilers work just as well with C++, I haven't seen C only compilers yet.

Yes you can. It's like saying you can't speak English without speaking German because they share some words. The structure is completely different and they both have plenty of things the other doesn't. After C99 C++ isn't even close to being a superset of C.

Quote:
Original post by by
I'm using C for kernel and OS design. C is the best alternative when it comes to the low level.

You mind explaining why? In my experience for the truly low-level stuff assembly is needed and for anything above that level both C and C++ should work equally well (some features of C++ like exceptions may not be reliable, but that doesn't make it useless). I realize most kernels is programmed in C, but this is either because they are really old or because that's just the way it has always been done. If C is a personal preference I understand it, but I have never seen why C is superior for low-level code. C++ can do most of the same things.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tojiro67445
Really? Admittedly I haven't used the Maya API for a while (since before the merged with Autodesk) but I was fairly certain that back then it was a C API.

It became 100% C++ somewhere around version 7, iirc. And it really makes plugin development so much easier. Here is more information about it. They also ship a Python API for those who dislike C++ (although that one shouldn't be used for performance critical tasks).

Quote:
Original post by Tojiro67445
Wouldn't surprise me if they've changed it since, but then it begs the question: How do they deal with the incompatibilities I mentioned previously?

They don't really have to. Often, a vendor will specify the compiler to use in order to write plugins for their software. For 99% of all larger applications (like Max or AutoCAD), that would be MSVS 2005. Binary compatibility is only one factor to consider, others are things like memory management, runtime compatibility, etc. So it's best to impose a compiler to the plugin developer for consistency and dev support issues.

When a new major compiler hits the market (as now with MSVC 2008), then usually the SDK is updated, or a new product version is released. You then have to recompile your plugin.

Share this post


Link to post
Share on other sites
Personally, I don't see a difference between C and C++
When I was taught C++, I was told that you can't have classes in C. C++ was object oriented and C was not. Then I don't know, things changed? Maybe the specifications got updated.

C++ then had STL. C could have classes.

I once came to these forums saying I'm coding in C++, I had a question in regards to memcpy, someone says I am not coding in C++ and starts an argument.

I don't know what the hell is going on. People just argue for no reason it seems.

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