7

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?

Kevin Montrose
  • 22,191
  • 9
  • 88
  • 137
Vaibhav
  • 6,620
  • 11
  • 47
  • 72

14 Answers14

15

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

MSDN.WhiteKnight
  • 664
  • 7
  • 30
sbi
  • 219,715
  • 46
  • 258
  • 445
6

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

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

Anywhere you need exact control of allocation of memory.

  • 1
    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++. – aviraldg Oct 11 '09 at 06:22
  • 1
    So you're saying C++ isn't used in physics, graphical games, finance, and statistics? OK then! –  Oct 11 '09 at 06:24
  • 1
    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 Oct 11 '09 at 06:24
  • 4
    @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 Oct 11 '09 at 06:27
  • @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. – aviraldg Oct 11 '09 at 06:32
  • 1
    @Aviraldg: You seem to be grinding the C axe a little. –  Oct 11 '09 at 06:39
  • 2
    @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 Oct 11 '09 at 06:45
4

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
  • 22,191
  • 9
  • 88
  • 137
  • 1
    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. – aviraldg Oct 11 '09 at 06:26
  • 2
    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 Oct 11 '09 at 06:27
  • 3
    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 Oct 11 '09 at 06:30
  • @kevin New sub-projects in GNU are *still C*. That's brand new projects without any codebase. – aviraldg Oct 11 '09 at 06:37
  • @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 Oct 11 '09 at 06:41
  • 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 Oct 11 '09 at 06:41
  • @Aviraldg: See http://www.research.att.com/~bs/blast.html for a quite complete discussion about criticisms of C++. – sbi Oct 11 '09 at 06:45
  • 1
    @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 Oct 11 '09 at 06:50
  • @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 Oct 11 '09 at 06:53
  • @sbi - Also, note that this great C++ compiler is itself written in C. – Chris Lutz Oct 11 '09 at 06:55
  • 1
    @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 Oct 11 '09 at 06:56
  • @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 Oct 11 '09 at 07:02
  • @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 Oct 11 '09 at 07:07
  • 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 Oct 11 '09 at 07:09
  • @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 Oct 11 '09 at 07:12
  • @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 Oct 11 '09 at 07:25
  • 1
    @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 Oct 11 '09 at 08:35
  • @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 Oct 11 '09 at 10:25
  • 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 Oct 11 '09 at 18:04
  • @Konrad: If you're writing C++ without classes, you gain function templates & ... what exactly? C++'s strengths all come from its OO underpinning, which we seem to agree is done better by more recent languages. My argument for C being non-legacy is its lingua franca status - along with Java, probably - and its near universal regard as the OS programming language. My statement of "C is not a subset of C++" was a counter-argument to new Gnome projects (which are in C) somehow indicating the liveliness of C++. @sbi: My argument never been "its obvious"; strawman a little less please. – Kevin Montrose Oct 11 '09 at 21:55
  • 1
    @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 Oct 12 '09 at 08:31
  • 1
    @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 Oct 12 '09 at 08:50
  • 1
    @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 Oct 12 '09 at 09:11
4

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.

Gant
  • 29,661
  • 6
  • 46
  • 65
3

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.

AndersK
  • 35,813
  • 6
  • 60
  • 86
  • 2
    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 Oct 11 '09 at 09:35
  • 10% less stuff on the screen when playing Freecell ***WOULD*** suck - I'd be missing 5.2 cards! – warren Oct 23 '09 at 07:36
1

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

Wael Dalloul
  • 22,172
  • 11
  • 48
  • 57
  • If you really want efficiency, then you'll want to use C. With ASM. – aviraldg Oct 11 '09 at 06:23
  • 3
    @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 Oct 11 '09 at 06:30
  • You wouldn't choose C++ for maximum efficiency. Perhaps maximum efficiency with some minimum level of maintainability. – Kevin Montrose Oct 11 '09 at 06:32
  • @chris Games are written in C++ because games heavily depend upon OOP. That and Kevin's comment. – aviraldg Oct 11 '09 at 06:34
  • 8
    @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 Oct 11 '09 at 06:38
  • 2
    @Aviraldg Games use C++ because it's fast, not just thanks to OOP but it definitely plays a part. – Jonas Oct 11 '09 at 09:47
  • 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 Oct 11 '09 at 11:46
  • @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 Oct 11 '09 at 12:33
1

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
  • 74,600
  • 47
  • 176
  • 233
  • 2
    Not necessarily before Java/.NET were introduced, so much as before Java/.NET had developed to a usable rate of efficiency. – Chris Lutz Oct 11 '09 at 06:32
1

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
  • 88,407
  • 13
  • 85
  • 165
1

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
  • 61
  • 3
1

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
  • 13,334
  • 2
  • 38
  • 57
  • 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) – Macke Oct 13 '09 at 18:02
0

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: 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.

Community
  • 1
  • 1
IanNorton
  • 7,145
  • 2
  • 25
  • 28
0

Most antivirus software are written in C++

NARKOZ
  • 27,203
  • 7
  • 68
  • 90
-1
  • 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
Satbir
  • 6,358
  • 6
  • 37
  • 52
  • 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 Oct 11 '09 at 07:15
-5

In legacy code...

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

Danny Varod
  • 17,324
  • 5
  • 69
  • 111
  • 3
    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. – aviraldg Oct 11 '09 at 06:26
  • 4
    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 S. Oct 11 '09 at 06:43
  • 2
    I like legacy code, it has that inimitable patina of antiquity. –  Oct 11 '09 at 07:00
  • through the answers above its proved u r wrong. – Vaibhav Oct 11 '09 at 19:55
  • 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 Oct 11 '09 at 21:17
  • You guys have no sense of humour - I blame too many C++ hours for that :-) – Danny Varod Oct 11 '09 at 21:20