tags:

views:

581

answers:

15

I've been asked many times by my juniors about the areas in which C++ is widely used. I usually answer Operating Systems. Are there any other areas where its extensively used?

+5  A: 

Numerical computations: physics, graphical games, finance, statistics;

Bit fiddling: drivers, operating systems, networking, embedded devices;

Anywhere you need exact control of allocation of memory.

Kinopiko
Blatantly wrong. I remember some code where I was kind of wondering why one large positive integer * another large positive integer == a small negative integer. Go figure. Almost any numerical computation will require a dedicated library in C++.
Aviral Dasgupta
So you're saying C++ isn't used in physics, graphical games, finance, and statistics? OK then!
Kinopiko
Good list. "embedded devices" should complete the list (even though many such apps now use java where possible, indeed java was invented for that the purpose of making such embedded applications more reliable, as these are often not easily updated)
mjv
@Aviraldg the fact that numerical computation libraries are in C seems to strengthen the validity of Kinopiko's list not making it so "wrong"... ?
mjv
@mjv,kinopiko Correction. Numerical computation libs are *in C, but for C* ie. any facilities provided with such libraries are part of the library and not the language C/C++ in contrast to languages like Python and Java.
Aviral Dasgupta
@Aviraldg: You seem to be grinding the C axe a little.
Kinopiko
@Aviraldg - The GNU MP BigNum has an allegedly quite pleasant to use wrapper for C++. C++ allows you to get the power of C combined with a few niceties, like operator overloading, that would make code using the GMP much easier to use and understand than having to look up all the `mpz_do_crazy_stuff()` functions.
Chris Lutz
+2  A: 

it's used where you find it solve your problems efficiency. Compilers, writing Drivers ...

Wael Dalloul
If you really want efficiency, then you'll want to use C. With ASM.
Aviral Dasgupta
@Aviraldg - I'm not even a C++ user, and you're wrong. There are some things that are actually more efficient in C++, and as compilers get better and better, the differences between C and C++ will shrink. Games (an area that needs high efficiency) have long been written in C++. You can (only) get efficiency in any language if you know what you're doing.
Chris Lutz
You wouldn't choose C++ for maximum efficiency. Perhaps maximum efficiency with some minimum level of maintainability.
Kevin Montrose
@chris Games are written in C++ because games heavily depend upon OOP. That and Kevin's comment.
Aviral Dasgupta
@Aviraldg: There's nothing in C++ that makes it inherently less efficient than C, except that many programmers understand too little of the language to know what individual features cost and when and how to apply them to certain problems. If you need polymorphism, a switch over a type enum as often done in in C is often less effective than C++' virtual functions (and using function pointers _is_ virtual functions - just without compiler support). When you want to do numerical applications, C++ can be as efficient as FORTRAN - only the code is more readable. See the >10 years old blitz++.
sbi
@Aviraldg Games use C++ because it's fast, not just thanks to OOP but it definitely plays a part.
Jonas
I've only worked closely with two or three ex-games industry C++ guys ( we were making a 'serious game' to train the army ), and they all avoided OO like the plague - going through hoops to make everything template driven and avoiding any virtual members if at all possible. Fast C++ is more about class oriented compile time polymorphism than object oriented dynamic polymorphism.
Pete Kirkham
@Pete: Modern C++ is certainly more about compile-time polymorphism and gains a lot of performance. Unfortunately, many shops (and that includes the game industry) aren't using modern C++.
sbi
A: 

In legacy code...

Even Stroustrup admits C++ has many mistakes, most inherited from C. That is why C++0x is being developed.

Danny Varod
While I'm not sure about C++, but C is extinsively used in the OSS world and the GNU/FSF world. Even today. So calling C or C++ legacy code isn't quite right.
Aviral Dasgupta
There are plenty of new C++ projects started all of the time. I work in motion control and we use C++ more than any other language. -1
Ed Swangren
I like legacy code, it has that inimitable patina of antiquity.
Kinopiko
through the answers above its proved u r wrong.
vaibhav
I write in C++ myself, doesn't mean its main use isn't legacy code, it just means there is too much legacy code :-)
Danny Varod
You guys have no sense of humour - I blame too many C++ hours for that :-)
Danny Varod
+3  A: 

I wouldn't say Operating Systems actually. The Linux & Windows kernels are mostly C, with only userland stuff being C++ (granted, drivers could be written in anything). I'm not sure about Mach (OS X), but I wouldn't be surprised if it were mostly C as well.

C++ filled this wonderful nitch of "Object Oriented, but fast enough for dinky computers in the late-80s & early-90s". Accordingly, anything written in the 90s had a good chance of being written in C++; applications, drivers, games, whatever.

Today, new development seems to be done mostly in managed (JVM/.NET) languages. Not that there isn't any new C++ development; games, in particular, are still performance limited enough to use C++ in many cases.

In short:

  1. Drivers
  2. Games
  3. LEGACY CODE
Kevin Montrose
While I'm not sure about C++, but C is extinsively used in the OSS world and the GNU/FSF world. Even today. So calling C or C++ legacy code isn't quite right.
Aviral Dasgupta
Mac OS X is based on FreeBSD, which is written in C. If anything, the OS X guys wrote the object-oriented stuff they needed in Objective-C.
Chris Lutz
C isn't legacy by any means. Also, by legacy code I mean anything *already written*. It doesn't need to be ancient, just extant. Naturally, additions to existing code will tend to be in the same language; likewise, I categorize such development as being on legacy systems.
Kevin Montrose
@kevin New sub-projects in GNU are *still C*. That's brand new projects without any codebase.
Aviral Dasgupta
@Chris: Except for some of OSX, that is C++. `:)` See the link ion my answer (http://stackoverflow.com/questions/1549990/1550034#1550034) for what this is.
sbi
I stand by C being a modern language. C++ is legacy in my opinion, as its niche has been co-opted by other, more modern, languages that are gaining significant mind share. Remember C != C++. C++ isn't even a proper superset of C anymore; there's not guarantee that valid modern C code will compile under a modern C++ compiler.
Kevin Montrose
@Aviraldg: See http://www.research.att.com/~bs/blast.html for a quite complete discussion about criticisms of C++.
sbi
@Kevin: And what does this show except a bias of the GNU people for C? And why don't I wonder, given some of the (embarrassingly wrong) criticism from Linus Torwalds towards C++? And yet, one of the best C++ compilers (and probably even the most wide-spread one) comes from the GNU people.
sbi
@sbi - The three libraries mentioned on that page are all outdated, and only one even made as far as OS X (but is dying in the Carbon/Cocoa transition), and only two of what's left really apply to OS X at all.
Chris Lutz
@sbi - Also, note that this great C++ compiler is itself written in C.
Chris Lutz
@sbi: I'm not sure where you're coming from. C is **the** language for development in all modern Operating Systems, that alone defines it as modern. It also remains one of the "lingua francas" of computer science. C++ was a good tool 20 years ago, and remains in use on projects dating from that time. I posit that better tools have since become available, displacing C++. How does that relate to Linus or gcc?
Kevin Montrose
@Chris: I didn't know the Finder was outdated. (I'm not a Mac user.) And GCC is older than C++, so it's no wonder it's written in C.
sbi
@sbi - Finder isn't outdated. I was referring to the three frameworks/libraries. But the Finder is the exception, one of the few places in OS X where they used C++, which probably caused the invention of the horrid hybrid Objective-C++ (which makes no effort to reconcile the languages' different object models).
Chris Lutz
My point is that the C++ compiler is written in C. In fact, GCC has compilers for Fortran, Java, and many other languages, all written in C. The only exception is that the Ada compiler is partially written in Ada.
Chris Lutz
@Kevin: Yes, C is used for OS development more than C. I never doubted that. But what you say about C++ is so blatantly wrong, I don't even know how to begin to argue that. 20 years ago, the decade of the standardization process hadn't even started, the STL wasn't dreamed of, and templates, the basis of all that's modern C++, had just started to be thought of by a few. By then, the number of users still doubled every year - usually not the sign of a well-established technology.
sbi
@sbi: Your objection seems to be to the phrase '20 years'. You're correct in that regard, as I meant to say 10. Typo on my part, you'll note though that my answer has always referred to the early 90s as C++'s explosive years. STL was finalized before 95, if I recall correctly. Visual C++ was released sometime around 91. I don't contend that C++ has *died* just yet, just that it is - and should be - **dieing**. I'm sure they'll still be C++ code around in 50 years though, languages hang on for a long time.
Kevin Montrose
@Kevin: Right now I'm not even using C++, but I started to learn it almost 20 years ago and I'm still learning. (That's something I see as an advantage of the language: it adapts and evolves.) _I have heard "C++ is dying" for 15 years._ Yet, it it's still there - and not only in legacy code. So I conclude it won't be dead for many more years to come. You're certainly free to disagree, but you'll have to bring better arguments than "it's obvious" for me to change my mind - I have too good a factual base for my estimate.
sbi
@Chris: I know that GCC is implemented in C (and I was even surprised to hear the Ada compiler has some Ada in it). And I already gave a good reason for that. Here's another one: C is something like the smallest common language almost all platforms provide. (That's because it's fairly easy to implement and allows to write code close to the metal.) In its role as a base for the compiler technology on just about all possible platforms, C was a very good choice (especially back then). However, that doesn't mean it's generally better than C++ (or anything else, FTM).
sbi
Calling C++, but not C, legacy, has to be backed up by arguments, please. “C is not a subset of C++”, while true, isn’t an argument. Kevin’s criticism of C++ seems to ignore (like most of C++’s criticisms) that C++ has other uses than OOP programming. For OOP, C++ is completely superseded by modern languages. But that is not the main field of C++. In particular, C++ excels in all areas where C is also used (provided there is a compiler) – most of the C code can be made simpler and less error-prone, while retaining all other criteria, in C++.
Konrad Rudolph
@Konrad: If you're writing C++ without classes, you gain function templates strawman a little less please.
Kevin Montrose
@Kevin: OO is more than just classes, and just using classes doesn't necessarily mean you're doing OOP. (STL has classes, but is not about OO at all.) C++' main strengths come from its ability to mix paradigms. That's where it shines very brightly. (Just look how powerful and easily techniques like type erasure mixes OOP with generic programming.) As for your argument: I have read again through everything you wrote in/under this answer. I found "...seems to be done mostly in managed...", "...has been co-opted by more modern languages..." and similar phrases. Quite unconvincing, if you ask me.
sbi
@sbi: You're working from a different definition of OOP than the rest of the world then. I also wouldn't call mixing paradigms a strength. If you read anything about maintainable C++, you'll be told to restrict yourself to some agreed upon subset of the language; exactly which subset differs, but still. Java's (a "managed language") uptake for enterprise, and likewise C# for new desktop applications is undebatable.
Kevin Montrose
@Kevin: I don't think at all that I'm alone in not categorizing the STL as OO - despite its use of classes. (And as for whether I read anything about maintainability: I've been in this industry for >10 years and had my share of decade-old multi-MLoC projects which restricted themselves to subsets of the language. Yuk.)
sbi
+1  A: 

Currently it is in game development and performance critical applications. However, there is lots of older stuff written in C++ which was mostly written before Java and .NET were introduced, and this code still needs to be maintained.

Naveen
Not necessarily before Java/.NET were introduced, so much as before Java/.NET had developed to a usable rate of efficiency.
Chris Lutz
+14  A: 

A quite large and probably quite definitive list of software written in C++ can be found at Bjarne Stroustrup's homepage.

sbi
+1 good answer.
Kinopiko
A: 
  • Several major operating systems have been written in c++
  • Uncompromising low-level efficiency essential for C++. This allows us to use C++ to write device drivers
  • Much numerical, scientific, and engineering computation is done in C++.
  • Graphics and user interfaces are areas in which C++ is heavily used.
  • C++ is widely used for teaching and research
  • Games
sat
The only operating system written in C++ was BeOS. The rest may use C++ in a few places, but predominantly use pure C.
Chris Lutz
+5  A: 

C++ is also used heavily in real-time financial market data software. Latency here is very important. C++ is great choice since it's almost the closest to metal.

m3rLinEz
A: 

C++ in Operating Systems: No kernels (the core bit that really does all the nasty work like memory management and drivers ) that I know of are written in C++, just C. Linux is written in C and so is Windows.

See here: http://stackoverflow.com/questions/580292/what-languages-are-windows-mac-os-x-and-linux-written-in

Applications ( non-kernel bits that make up an OS ) these days are written in whatever language seems best for the job.

You would choose C++ if the following were important to you:

  • You want to make heavy use of classes and inheritence
  • You only plan on working on one OS
  • You want reasonable performance
  • Your developers already know C++
  • You want to divide work on similar components to different people or teams ( you can give each time a class or interface to implement )

You can do all of the above with C, portability between platforms is still an issue ( C++ is equally platform specific as most C ) In C you have to be more strict make good use of static and dynamic analysis tools. It's easier to leak memory in C than in C++ too.

IanNorton
A: 

Consider this: From the introduction of MFC until the introduction of the .NET framework, C++ was the preferred language for Windows development. So that should tell you something. Preferred by Microsoft that is, many developers still prefer it to .Net languages.

C++ is a language capable of systems level programming, but also due to the provision of extensive libraries it is used for applications programming also. I would guess that almost every application running on your Desktop PC was written in C++.

If you can get a library for anything, you can almost certainly get it for C++.

It is widely used in the games industry, and to some extent in the embedded systems domain.

So I would say - 'everywhere'. It is after all a 'general purpose' programming language.

Clifford
+3  A: 

C++ and C are used heavily in embedded systems since one can have deterministic control of memory and other scarce resources. I think most games (well at least the games I play) are still written in C++, probably because there exists large frameworks written in C++ which have been fully tested and are very capable.

Anders K.
And because games also need deterministic control over memory and system resources. They are also performance-critical, so even a language that is "only 10% slower" than C++ is unacceptable (unless you'd be happy with a game that had 10% less stuff on screen).
Crashworks
10% less stuff on the screen when playing Freecell ***WOULD*** suck - I'd be missing 5.2 cards!
warren
+1  A: 

I have seen C++ used quite heavily in GUIs, due to the object orientated nature being sort of natural for "widgets".

I once saw it used in safety-critical code for an aircraft. This still gives me nightmares.

Jon Ward
I've seen C++ code in places that would give most people nightmares too :-)
Danny Varod
+1  A: 

Any application based on Qt will use it as Qt is written in C++.

Also, since KDE is based on Qt pretty much the whole desktop environment including the applications designed to work within it are therefore written in C++.

Troubadour
There's PyQt, which brings Qt for python. (There's also another totally open-source bridge for Python<->Qt in the works, but I've forgotten it's name)
Marcus Lindblom
+2  A: 

Around Basingstoke apparently.

(unemployed C++ guy in Glasgow)

Pete Kirkham
Sorry for you, but at least you've kept your sense of humour.
Clifford
A: 

Most antivirus software are written in C++

NARKOZ