views:

912

answers:

21

When I was in college 20-ish years ago, C was our language of choice because at the time it was almost the only game in town as a general-purpose programming language. We learned to program using C. It was used for systems programming, data structures, operating systems, and just about everything else. Text-based console I/O was the primary way to interact with the computer. GUIs were rare and web programming didn't exist at all.

Roll the clock forward 20+ years. We have a plethora of languages that specialize. For example, PHP is good for web programming. One would be crazy to write a web app in C, but likewise it would be insane to do systems programming in PHP.

I don't write in C anymore. I'm out of the loop, so to speak, about current industry uses of the language. I know it's used for kernel development, microcontrollers, and the like. What else?

What are the key industries that use C because it's the best language for the job? For what kinds of applications is C the preferred choice?

+3  A: 

Embedded devices, trading algorithms, sound processing algorithms, drivers, Linux Kernel, etc.

gersh
And more controversially, git. :-) http://bit.ly/5puz
Justicle
@Justicle, that is an awesome post. Thanks.
asveikau
A: 

I know that low-level drivers tend to be written in C because of the straightforward pre- and post-conditions for any given instruction. I have a friend who writes low-level device drivers for a flash memory company and all of the code he writes is in C.

fbrereto
+10  A: 

I use C for non-systems programming. My work is related to bioinformatics. The reason I use C is because there is a lot of very good C libraries, and the routines are very processor intensive.

C is also easily bindable to other languages. So you can build a library in C and have it work with C++, Python, Java, .NET, Ruby, PHP etc. It's not as straightforward in the reverse.

joemoe
+4  A: 

Anything close to the hardware - device drivers and embedded systems most prominently. Things where the abstraction level of C is helpful to provide some portability but anything more would get in the way.

Michael Borgwardt
+7  A: 

Reasons why one might see new C code written include:

  1. Code that still needs access to the "bare metal" (device drivers, etc.).
  2. Library routines (callable from other languages, please) where performance is crucial.
  3. Interoperability with existing C code base.
  4. Environments (e.g. embedded controllers) where severe resource constraints limit solutions.

True, general-purpose application code (especially where there's a human in the loop)... not so much.

joel.neely
+14  A: 

One of the most important features of C is its portability. On x86 you pretty much have every programming languages, but on some other architectures, C is frequently the only choice in addition to assembly. Another meaning of portability is, as someone has pointed out, most other programming languages have C bindings. When you have a C library, you can relatively easily have Perl or Python APIs with a comparable speed to the native C library. In addition, C compilers are usually much more robust than C++ compilers and more matured. Someone told me that this is one of the many reasons that why Linux kernel is written in C.

A: 

Application I work on (box that controlls IP camera systems) started out in C because we were initially developing it for a very small embedded system and C++ didn't work in uclibc environment. Over time we switched to regulac libc, but the app core is remains in C. There are some parts where we would benefit from object-oriented design and exceptions, but I think the langauge still works well for us.

che
A: 

Games, especially console games and the servers for MMOs.

sean riley
And the clients for MMOs too.
Crashworks
A: 

Distributed Version Control Systems like git

OscarRyz
+1  A: 

In my current role, we generally only write C code when modifying legacy systems (VXWorks Kernel) or occasionally for simple tools or programs.

C is also insanely portable; (just about) every O/S and Kernel has a C compiler - so for applications that demand such support, C is one of the best options available.

C++ is seen as generally superior to C, though my understanding is that in under strict conditions, C compilers are preferred - conditions such as low-level drivers, small embedded systems, etc.

And call me old fashioned, but I think that C is the best language to teach to novice programmers - PHP, C++, Java ... these are all C-like in syntax - I began learning C 10 years ago and now feel confident to tackle any programming language. And then there's the issue with all these graduates not understanding memory management... :(

Josh
A: 

Robots.    

Crashworks
I don't know about your robots... but all my robots are programmed in logo :-)
Jason Whitehorn
+1  A: 
Michael E
At GUADEC in 2007, I suggested to the GTK maintainers that GTK 3 be rewritten in C++ "under the hood", while retaining the current C bindings. It's certainly feasible, and don't think anybody considered it impossible, but it didn't exactly meet with a warm reception.
Bob Murphy
+3  A: 

I'm doing mostly Linux work these days, and an astonishing amount of Linux code is written in C rather than C++ or something else.

There are very good reasons the Linux kernel, and for that matter, other kernels like Darwin, the various BSD distros, and so on are written in C. Here are a few:

  • C has often been called a "portable assembly language". It's fairly easy to mentally "compile" simple C statements for the target CPU and imagine what's going to happen, in terms of instructions and registers and so on. And you really want to be able to do that when working on an OS kernel.

  • There are a lot of library routines you simply can't use in a kernel, like malloc() or printf(), because they're unsafe in that context. You have to use special kernel equivalents, instead. The problem with C++ is that a lot of things people consider fundamental language features, like the new operator or iostreams or automatic object construction on the stack, would not be safe in the kernel in their default configurations. You might be able to hack something up that would work, but it's a lot easier to stick with the known, working solution, which is to use C.

  • The code base is already written in C, and it would be a huge job to convert it to C++.

  • For a given CPU architecture, the code generated from C is pretty standardized. Not so with C++, particularly for things like templates and inline functions. The machine language from C++ is pretty unpredictable, and some C++ compilers produce really bloated code. That's not something you want in a kernel, whose code needs to be as predictable, fast, and small as possible.

A lot of other "user space" functionality in Linux is written in C, too. Some of the components I work on that are that way include X Windows, GLib/GObject, GDK/GTK, Cairo, Pango, and Clutter. All of these could have been written or rewritten in C++, but there seems to be an preference for C in the Linux world.

Bob Murphy
A: 

Set-top, Digital TVs and embedded systems are still using "C" for Application development.

subbul
A: 

most embedded systems, HPC applications (lot of fortran here too), operating systems, lot of unix apps (apache and sendmail comes to mind)

the compilers/interpreters for most other languages may also be contain C to varying extents !

Gautham Ganapathy
+1  A: 

This link will give you some more details.

http://in.answers.yahoo.com/question/index?qid=20061001065014AA0Wkkt

FIFO
A: 

To make an application scale better. C, being many times faster than higher-level languages, can be used to replace the functions that might "bog-down" such as searches. And its portable - with only minor changes the same C program will work on Linux and Windows.

Peter Erskine
A: 

As somebody pointed out, C is used where you are programming close to hardware, this is one of the main reason C is used in many robotics applications. There are numerous cross-compilers which let you code in C and then port the code onto a micro-processor, micro-controller, embedded device and even DSP processors. There are even special languages based on C like nesC which are used specifically to program short range wireless sensors.

Even for heavy industrial robotics, you would find that low-level controller programming is done in C and then the engineers, put Java or C# GUI which interacts with extensive C libraries.

wiznick
A: 

One subject which hasn't yet been mentioned is speed. While many compilers of higher-level languages do a good job, if you have an application which needs to run extremely fast or a small inner loop of code which is called many times in a performance-critical environment, well-written C code can often do the job better than most other options short of machine code.

Tim
A: 

C/C++ are also used for speed, so things like video games are still written in C/C++. Real Time trading applications are probably written in C as well.

Jack Marchetti
A: 

Language development so we don't have to write in C.

python - http://svn.python.org/view/python/trunk/Parser/

php - http://svn.php.net/viewvc/php/php-src/trunk/main/

perl - http://perl5.git.perl.org/perl.git/tree

lua - http://www.lua.org/ftp/

Nick