109

I am a C# programmer, and most of my development is for websites along with a few Windows applications. As far as C goes, I haven't used it in a long time, as there was no need to. It came to me as a surprise when one of my friends said that she needs to learn C for testing jobs, while I was helping her learn C#.

I figured that someone would only learn C for testing if there is development being done in C. From my knowledge, all development related to COM and hardware design is also done in C++. Therefore, learning C doesn't make sense if you need to use C++. I also don't believe in historic significance, so why waste time and money in learning C?

Is C still used in any kind of new software development or anything else?

Monomeeth
  • 103
  • 3
Pankaj Upadhyay
  • 5,060
  • 11
  • 44
  • 60
  • 47
    Have you ever seen a C++ compiler for PICs? – SK-logic Aug 26 '11 at 12:33
  • 3
    All are great answers and have added great value to the question. Thanks – Pankaj Upadhyay Aug 26 '11 at 12:50
  • 1
    I am bit confused. All answers provide a one or two good points. Please vote for the ones you like. I will mark the most voted answer as the approved one as i can't judge which one is more better than the other. – Pankaj Upadhyay Aug 26 '11 at 12:58
  • 207
    Am I the only who is sad that somebody would equate learning with wasting time and money? – Jetti Aug 26 '11 at 14:59
  • @Jetti , i second you as i keep on touching new things every day. The essence of question was not this what you take out of it. You can edit the post. – Pankaj Upadhyay Aug 26 '11 at 17:42
  • @Pankaj Upadhyay - It isn't just you, I've seen it a lot on this site and on others. Also, I figured it was mostly just a poor wording of what you really wanted to express. – Jetti Aug 26 '11 at 17:48
  • Ya dats the case. Actually its the way my friend was putting, so i mugged up the words. While learning C#, she said she wants to go in C testing jobs so learning C# is a waste. Therefore i made the mistake of referring C in the same way. – Pankaj Upadhyay Aug 26 '11 at 17:55
  • 1
    while not the best or most reliable site on earth, check out www.langpop.com – Vinicius Kamakura Aug 26 '11 at 17:56
  • 37
    "*In my knowledge, all the development related to COM and hardware design are also done in C++*" - Sounds to me like you don't actually do any hardware interface design. – Ed S. Aug 26 '11 at 18:47
  • 3
    Veracity is new development, and being done in C. "We chose to write it in plain old C to give us flexibility in porting to more exotic platforms in the future." http://veracity-scm.com/qa/questions/254/what-makes-veracity-different. – Shannon Severance Aug 26 '11 at 18:49
  • @Ed S. : +1, To be honest, post 6 hours asking this question, i feel the same. Actually I never used C and neither done any hardware interface development. Therefore, in my own small world, i thought C is a legacy language and that's it. But now, I am astonished to learn its the most widely used language still, keeping java aside. – Pankaj Upadhyay Aug 26 '11 at 18:51
  • 1
    Some JVMs are written in C as well, HotSpot is mostly C++. – Ed S. Aug 26 '11 at 18:56
  • C is a dead language. People haven't used it since the mid 60's for anything serious other than academia, and even then, Fortran rules that world. – Thomas Eding Aug 26 '11 at 20:20
  • 5
    A comment that isn't getting much attention on this thread is that each tool has a general purpose. Higher-level languages are great for some things, and not others. Same with when you go to slightly lower-level languages. Just because you haven't found a purpose for C doesn't mean it isn't heavily in use elsewhere. Likewise, I can name a a bunch of engineers who hate this "overly abstracted crap" used on a daily basis to churn out the applications that keep entire industries alive. – Brad Aug 27 '11 at 03:42
  • I can't believe no one raised up the most important point (IMHO), obvius... =P ...throwing an answer.. – H_7 Apr 01 '12 at 23:50
  • @SK-logic: that's besides the point but yes, there are C++ compilers for PICs ! http://www.sourceboost.com/Products/BoostCpp/Overview.html – Julien Lebot May 26 '12 at 13:27
  • 1
    The minus 1 is for asking a question that is answered by the wikipedia article on C. – philosodad May 26 '12 at 13:36
  • 35
    People forget that the fancy higher level languages that we all love are often implemented in C. – David Cowden Jan 15 '13 at 22:03
  • 1
    "I also don't believe in historic significance, so why waste time and money in learning C?": Nobody forces you to learn C if you do not find it useful, and the fact that there are plenty of developers, also young ones, who still use it , should be enough of a proof without the need to ask here. It seems you have posted this question to challenge people to convince you of the contrary, and possibly starting a flame war. – Giorgio Jan 16 '13 at 12:09
  • 16
    @ThomasEding Dead language? You certainly have a very limited knowledge of programming languages if you consider C a dead language. – JesperE Mar 03 '13 at 14:57
  • @JesperE I think Thomas was displaying sarcasm when he wrote C is dead 18 months ago ;) – jwenting Mar 04 '13 at 14:05
  • Quite possible, but how can we tell? – JesperE Mar 04 '13 at 14:36
  • 3
    duplicate of: [What makes C so popular in the age of OOP?](http://programmers.stackexchange.com/questions/141329/what-makes-c-so-popular-in-the-age-of-oop) – gnat May 08 '13 at 21:23
  • Really? All legacy system I can ever think of either uses C completely or under workshare with ADA, FORTRAN, etc. You are C# which is practically Microsoft's answer to Java. – ha9u63a7 Jun 28 '13 at 08:41
  • Funny enough, another person is quite interested in establishing that C/C++ is not a HLL [here](http://programmers.stackexchange.com/questions/203024/why-not-have-a-high-level-language-based-os-are-low-level-languages-more-effici). – ha9u63a7 Jun 28 '13 at 11:15
  • @hagubear i am not really sure as to why you think this question is funny or doesn't make sense. – Pankaj Upadhyay Jun 29 '13 at 06:05
  • A fair bit more than C#, that's for sure. – Miles Rout Aug 24 '16 at 00:59
  • Linux & embedded is where C rules. I love C but the libraries are abysmal b/c they all have the most minimal degree of abstraction (due to the lack of classes, generics, and overloading). But even w/ all that good stuff (i.e. C++) you still come across libraries and frameworks like Boost, QT, COM, and ATL where there is a greater degree of abstraction but at the cost of complexity. C# reduces the complexity by removing pointers, using GC, using attributes instead of template metaprogramming, etc. This results in C# having better libraries than C or C++. Also C# is open source now! – annoying_squid May 03 '17 at 13:11
  • 3
    C is traditionally portable assembler. This role is being taken over by Javascript. – Thorbjørn Ravn Andersen Jan 18 '18 at 08:57
  • I use it almost every day developing for iPad/iPhone. Many libraries are written in C and don't have an Objective-C equivalent. So yes, it is still used, and by one of the newest device on market. With C, you can program lots of embedded systems, it's small and handy, and probably will be around for many years to come (aka you are not wasting time nor money learning it) – Rad'Val Aug 27 '11 at 16:16
  • Portability. Do a list of every system you think will run C code and then a similar list for every other language you like. If you came up with the same answer as me then the conclusion is yes. – tidbeck Aug 27 '11 at 10:21
  • check out [langpop.com](http://langpop.com/), especially the graphs from Freshmeat and Google Code. It shows that C still is way ahead. C is still popular on systems where you need to be get close to the metal (ie embedded system) and performance hungry applications. – tehnyit Aug 26 '11 at 12:40
  • Generally for embedded system C is still widely used. This [question](https://softwareengineering.stackexchange.com/q/37684/9449) gives some other example. The [Tiobe index](http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html), which attempts to classify language by *popularity* / *usage*, consistently puts C in the first places. – Xavier T. Aug 26 '11 at 12:39
  • See also http://norvig.com/21-days.html for an interesting opinion – Basile Starynkevitch Jun 01 '20 at 16:33
  • I use C. Many of the programs I use/write, need operating system access, along with the requiring quick performance. As well, small size is important. A 5 second delay is too long an execution time for one program that edits a very complex system files. – Leslie Satenstein Aug 12 '22 at 01:43

12 Answers12

227

C has the advantage that it is a relatively small language, which makes it easy to implement a C compiler (whereas a C++ compiler is a monster to write), and makes it easier to learn the language. Also see the TIOBE index, according to which C slightly ahead of C++.

In (IMO) decreasing order of justification, C is still used a lot for

  • Embedded stuff
    It's way easier to port a C compiler to a small platform than it is to port a C++ compiler. Also, C advocates claim that C++ "does too much behind their backs". However, IMO that's FUD.

  • Systems programming
    Again, that's usually due to claims that it is easier to "know what the compiler is doing". However, many embedded programs would benefit from, e.g., templates and other C++ key features.

  • Open source software
    That's mostly an attitude problem, though: OSS has always preferred C over C++ (whereas it's the opposite in large parts of the industry). Torvalds' irrational hatred might actually be the most important reason for this on Linux.

sbi
  • 9,992
  • 6
  • 37
  • 56
  • 17
    It's more history than attitude. Many of what you might consider the "core" open source packages were originally developed when C++ wasn't as widely available as it is now and resources were still scarce. – Blrfl Aug 26 '11 at 14:07
  • 2
    @Blrfl: Linux turned 20 years today. 20 years ago we did have C++, although I agree that C++ without smart pointers and STL looks bleak from today's POV. – sbi Aug 26 '11 at 17:48
  • 3
    Hmm.. building a C compiler is deceptively complex. Not like a C++ compiler of course; but C isn't as simple to implement as some make it out to be. (E.g. Pascal is a simpler language to implement) – Billy ONeal Aug 26 '11 at 17:57
  • 6
    @sbi: Most of what I consider the core stuff (GCC, bash, tcsh, Emacs, X perl, screen and a very, very long list of others) was developed before Linux existed. You won't find much of anything in that category of software that was developed in C++ during the 1980s. I was there, and it just wasn't happening. – Blrfl Aug 26 '11 at 18:30
  • 74
    The TIOBE index is a joke. Search engine hits are meaningless. – DeadMG Aug 27 '11 at 11:08
  • 3
    @Blrfl: Actually I know that (and therefore my comment did not explicitly disagree with you). However, there have been a few OSS projects started since, and many of them still stick to C rather than using C++, often for rather irrational reasons. – sbi Aug 27 '11 at 11:16
  • 3
    A basic working C compiler, as opposed to a useful optimizing one, is rather simple. See `pcc` or even `tinycc` for examples... – R.. GitHub STOP HELPING ICE Aug 28 '11 at 00:22
  • @R, a heavily optimising compiler is easy to build now, with such a great toolchain as LLVM. – SK-logic Aug 28 '11 at 10:37
  • 2
    Why would an embedded program benefit from templates? They generally blow out binary size and were specifically _removed_ from [Embedded C++](http://en.wikipedia.org/wiki/Embedded_C%2B%2B). – Aidan Steele Aug 29 '11 at 01:49
  • 32
    @Sedate: That templates _generally_ cause code bloat is a myth, coming from the times of ancient C++ compilers. Modern compilers will fold identical template instances. OTOH, templates allow template meta-programming, which executes code at compile-time, rather than run-time, resulting in _less_ code being generated. Also, they make for much safer programs (less casting), something that's often very important in the embedded domain. EC++ has been bashed to death by C++ experts over (among other things) the sheer stupidity of throwing out templates. – sbi Aug 29 '11 at 06:25
  • 3
    @sbi: If you can find "modern compilers" for anything other than the most common AVR and PIC chips, I'll be very impressed! I'm well aware that great improvements have been made in "consumer-level" compilers (for want of a better word), but these do not often translate to compilers for small micros. – Aidan Steele Aug 29 '11 at 08:26
  • 5
    @Sedate: I have no experience in this field, but from what I understood GCC is available on many embedded platforms, and it comes with quite a good C++ compiler. But even if it's not, then there's the old chicken-and-egg problem: Why should vendors put money into licensing a good compiler when their users still believe in old FUD statements, don't even _know_ about C++' features, and do not plan to learn about them? (EDG licenses the best front end money can buy, Comeau, based on EDG, ports their compiler to any platform for little money, and the GCC/Apple deal could be copied by others, too.) – sbi Aug 29 '11 at 09:49
  • 1
    This compiler seems to support some advanced feature of C++: http://www.sourceboost.com/Products/BoostCpp/Specification.html I haven't touched PIC embedded programming for years now, but I remember finding another C++ compiler back then for it (I think it was IAR) and that's what got me started on C++ dev on Linux first, then Windows. – Julien Lebot May 26 '12 at 13:34
  • 5
    Torvalds hatred is actually pretty rational! The things that turn him off C++ are real turn offs for anyone who just wants to develop efficient, portable, multi-platofrm software. – James Anderson Nov 01 '12 at 01:52
  • 22
    @James: You mean things like efficient abstractions, generic programming and type-safety? Yeah, who'd want that. – Xeo Nov 04 '12 at 21:34
  • 11
    @James: Might I kindly point you at [this comment](http://programmers.stackexchange.com/questions/103897/is-the-c-programming-language-still-used/103904#comment188296_103898), where there's a link to a posting in which someone earnestly takes Linus' rant as if it was something intelligible, and takes it apart sentence by sentence. Write a reply to that that's at least half as intelligent as that one and post the link here. Or go back to the cave you came from, and keep cargo-culting. – sbi Nov 04 '12 at 21:38
  • 8
    @sbi -- The problem is every argument you can make for using C++ rather than C, there is a better argument for using a higher level language like Java, Scheme , or Python et all. Similarly every argument you make for using C++ rather than Java et. all. there is a better argumant for using just plain C. – James Anderson Nov 05 '12 at 01:56
  • 8
    No, @James, the problem is that, whatever argument is presented, some C-zealot will still yell "but code-bloat!" and "it's doing stuff behind my back!" while covering his eyes and plugging his ears. _And that's just the rational ones._ The others do as Torvalds does, say things like _"you are full of bullshit"_ instead of making any points, and honestly believe that this is any argument other than for them being infantile. – sbi Nov 05 '12 at 08:47
  • 4
    @James: And unless you manage to explain why there is no room between portable assembler (you do know that C was created as such, don't you?) and half-interpreted languages on virtual machines, I will have to decide which of those categories to put your "argument". – sbi Nov 05 '12 at 08:48
  • 2
    "That's mostly an attitude problem": I do not think C is used more often in OSS than in the industry, and even if that were the case, I do not think it would be an "attitude problem" due to prejudice. -1 – Giorgio Jan 16 '13 at 12:06
  • 4
    Well, C++ *is* doing lots of stuff behind your back. Whether or not it is good or bad, that's another question. But fact is that it is much more difficult to understand what kind of code a typical C++ program is going to be translated to than a typical C program. There is a complexity there which burdens a C++ programmer more than it does a C programmer. – JesperE Mar 03 '13 at 14:50
  • 13
    @JesperE As it happens, I have changed jobs since I wrote that, and I am now programming for embedded devices. We're using C++, and it's remarkable what the STL and template meta-programming can do for you when you have weak hardware and hard realtime constraints as well as reliability necessities. (We're doing power plants.) Yes, you have to know whether you should use a `std::vector` or an `std::map` for a certain piece of code — but you do not have to implement it yourself, but can rely on well-tested, highly performant, and dependable library implementations offering high abstractions. – sbi Mar 03 '13 at 21:21
  • 4
    The problem with high-level abstractions in C++ is that many of the abstractions are **leaky** (http://www.joelonsoftware.com/articles/LeakyAbstractions.html), which means that you often need to understand the underlying implementation anyway. My favorite example of this is the "static initialization order fiasco": http://www.parashift.com/c++-faq/static-init-order.html. C++ certainly has some good features, but they also offer you many new chances to shoot yourself in the foot. – JesperE Mar 04 '13 at 06:51
  • @JesperE In my whole C++ experience, I've never had to read implementation of standard library I was using. And yes, I wrote embedded stuff too. Neither I had or wanted to look at assembly code; if I wanted to use assembly, I'd write in assembly, but any other language (C is *not* an exception here) was made to provide, uh-oh, abstraction over it and machine code. Now, do you understand implementation of C standard library you are using? – Bartek Banachewicz Mar 04 '13 at 08:05
  • @BartekBanachewicz yes, I've had to step through STL/Boost code as well as C standard library functions all too often to figure out weird crashes. I cannot claim to understand all of the C standard library, but the C standard library is **definitely** easier to grasp than the C++ one. – JesperE Mar 04 '13 at 08:18
  • Easier to grasp? But of course, these two are hardly comparable in terms of functionality, so it's rather obvious that C++'s std implementation is more complicated. Notice however how at the same time C++ containers prove to be much simpler and less error prone to use. That's the point of the library after all, don't you think? – Bartek Banachewicz Mar 04 '13 at 08:27
  • 3
    @JesperE: IMO the only time the STL abstractions are leaky is at compile-time, e.g. when you pass `std::list` iterators into `std::sort`, and all hell breaks lose. Otherwise it's a damn well-created abstraction. And if you feel you need to step through std lib code, you're likely doing something wrong. I cannot remember having needed to step through either `std::printf` or `operator<<` for built-ins. I have indeed looked at their code, though, to satisfy my curiosity, and I certainly think they are both mostly unreadable. – sbi Mar 04 '13 at 09:18
  • 3
    There are so many, many, places in C++ where the abstractions are leaky (i.e. where you need to know the underlying details in order not to step on any mines), but many C++-programmers are so home-blind that they just see it as the way things work. I really suggest that you read Joel Spolskys artikle on leaky abstractions. It will make you a better C++-programmer. – JesperE Mar 04 '13 at 09:36
  • 4
    @JesperE: I guess I first read that article a decade ago. And you might have a point about programmers being home-blind about their beloved language — but this applies to C programmers just as well, so it's not an argument pro or contra either side. – sbi Mar 04 '13 at 11:00
  • But C programmers typically do not boast about the superior abstractions of C, rather the opposite. I think Damien Katz makes a good point of C being "honest about its tradeoffs". http://damienkatz.net/2013/01/the_unreasonable_effectiveness_of_c.html – JesperE Mar 04 '13 at 12:58
  • 4
    @JesperE: Indeed, C programmers instead boast about how C++ is so bloated and how it does things behind your back. Full circle. HAND. – sbi Mar 04 '13 at 13:38
  • 8
    You seem to be treating this as a boxing match, where we have to determine who of C and C++ is going to win. Fact is that both C and C++ is out there, and not acknowledging the problems in the tools you work with is not going to make you a better programmer. Yes, C programmers bitch about C++ and vice versa, but trying to select a winner is meaningless. – JesperE Mar 04 '13 at 13:46
  • These comments would have you believe that C++ compilers are essentially 'perfect'. The reality is, that C++ has runtime requirements that are hidden from the developer, and any ASM dump will confirm this - even with simple container class templates, iterators, move semantics, lambdas, etc. For example: 8-bit AVR gcc generates compact code, whereas a C++ runtime will probably break the EEPROM budget. –  Apr 17 '15 at 15:57
  • @user103164 There are three sources of that I know of. Code to run constructors/destructors at static init/deinit which is tiny and you can avoid, and exceptions and runtime type information both of which gcc and most other compilers will let you toggle off. – Joseph Garvin Jul 17 '17 at 01:50
  • It's sad that no answer mentions legacy software. Personally, I use C only to maintain legacy software. For an existing application with 20 data processing programs written in C, I'll still choose to develop a new one in C just to keep it coherent. – Etsitpab Nioliv Jul 27 '17 at 08:25
  • 2
    @EtsitpabNioliv: While people do that, it's not a very good reason. C++ was made compatible with C deliberately (and at great cost, given C's abysmal syntax). You not taking advantage of that by writing new code in C++ is just bad. – sbi Jul 27 '17 at 14:29
123

C is used a lot in embedded hardware programming where resources are scarce.

Linux kernel is written in C because, according to Linus Torvalds, C++ is a horrible language.

Thomas Owens
  • 79,623
  • 18
  • 192
  • 283
Joonas Pulakka
  • 23,534
  • 9
  • 64
  • 93
  • 15
    I think large part of Windows kernel is also C. And a lot of legacy systems. – Coder Aug 26 '11 at 12:38
  • 16
    To be complete, Linus did give a try to C++ in the kernel. That was more an issue than a plus. Anyway, kernel devellopement is a really specific topic, that doesn't means C++ is bad in general. – deadalnix Aug 26 '11 at 12:40
  • 79
    According to [others](http://warp.povusers.org/OpenLetters/ResponseToTorvalds.html), Linus' argumentation is horrible. – sbi Aug 26 '11 at 12:41
  • 37
    Linus's arguments may or may not be valid, but Linux kernel is still written in plain C :-) – Joonas Pulakka Aug 26 '11 at 12:51
  • 13
    As a side note: [BEOS](http://en.wikipedia.org/wiki/BeOS) was written in C++ and superior to other OS of its time failing mainly due to the politics of the day. As an indication that the OS need not be written in C. – Martin York Aug 26 '11 at 13:00
  • 10
    Linus doesn't present the best argument, but I understand where he's coming from. Unfortunately the response to Linus' rant completely misses the point. It deconstructs from the typical academic view which is, quite honestly, not of much use when trying to debate a pure "doer". Fundamentally incompatible life views, not even enough common ground to have a decent discussion. – Brian Knoblauch Aug 26 '11 at 13:18
  • 7
    Going along with what Martin said, it's worth noting that in the mid 1980s through the early 1990s, Apple was building the most advanced OS the world had yet seen... in Pascal. – Mason Wheeler Aug 26 '11 at 17:23
  • Um, BEOS was awesome in many ways, but not far superior. It's network stack was pretty bad. Bad as in flaky and slow. – Kyle__ Aug 26 '11 at 18:49
  • 5
    Just to note that Linus' view is shared with **all** the programmers in "coders at work" (and almost every other master programmer I know of). – Philomath Aug 28 '11 at 02:54
  • 1
    @Brian, agreed. The response would have been much better founded if the author listed what large software projects he had personally been involved with writing non-trivial amounts of code in. Also having written a note called "Why C++ is vastly superior to C" gives a hint that the author might be as biased as Linus. http://warp.povusers.org/programming/cplusplus_superior_to_c.html. Quote: "The internet is full of people defending C as the superior language, and denigrating C++. These people are complete idiots and morons, and they have absolutely no idea what they are talking about." –  Aug 28 '11 at 12:54
  • 5
    @Philomath: How many of those are "master programmers" in C++? How many of them are "master programmers" when it comes to kernel development? Appeal to authority isn't much of an argument. – jalf Aug 29 '11 at 09:55
  • 5
    I read his response again now that I can partially understand it, and Linus just seems to be trolling OOP in general. Its hard to take his email seriously with all the trolling in it; its barely an argument based on facts – TheLQ Aug 31 '11 at 04:32
  • 1
    @Philomath: Actually this is only true for the OSS world. The industry has long since moved on to C++. And, of course, believing that C is superior you wouldn't hear about C++ "master programmers". But no list of "master programmers" would be complete without Alexandrescu and a few others who most definitely do not share Linus' POV (if that rhetoric hatred rant can even be called a "POV"). – sbi Oct 09 '11 at 20:24
  • @ThorbjørnRavnAndersen: The difference is that in your link, the author offers real examples of how C++ is much easier and safer to use. Linus just rages. – DeadMG Oct 12 '11 at 15:26
  • 2
    @DeadMG: The author at that link also totally misses Linus' point about abstraction. Linus says that there is no abstraction, it's straight bits and bytes, and the author responds with abstractions are good and more maintainable and thus should be used. Which is exactly the scenario Linus is complaining about. The author has some points about Linus' post but they really boil down to Linus was participating in a discussion, not writing up a language evaluation report. Treating it like a scholarly report is a mistake. – jmoreno May 26 '12 at 16:24
  • 8
    with all my great respect to Linus, which has achieved tons of things I am not even able to achieve... it's really sad Linus should be not inteligent enough to understand C++ and STL. It's just so obvious that he has no argumentation. **Linus uses words like "piss off yeah piss you off you full of bullshit"**: This is the level 0 for communcating and doesn't show an objective point of view. – Stephane Rolland Aug 14 '12 at 19:54
  • C share in embedded software is till very high check this [C trend graph](http://i.cmpnet.com/embedded/2009/0709_July2009/0709esdBarr01.gif), [Ref](http://embeddedgurus.com/barr-code/2009/11/embedded-programmers-worldwide-earn-failing-grades-in-c-and-c/) – Abdurahman Jan 16 '13 at 11:51
  • 2
    C is much faster to compile. Particulary useful when compiling kernel and modules as it's a lot of code. – k3a Nov 20 '14 at 09:42
  • 1
    For kernel code my yardstick is "How easy is it to look at a piece of code and count potential cache misses?" (it's important for code expected to run in cold cache conditions, and/or involving "bare metal multi-CPU"). The entire point of the abstractions in C++ is to hide low level details, and for kernel development those low level details are necessary information that need to be obvious and not hidden. I think this is why Linus has said one of the reasons he doesn't like C++ is that "C++ programmers use it" (people who don't think "too high level" abstractions are a problem). – Brendan Nov 08 '17 at 11:50
  • @StephaneRolland: I hope that one day my colleges have so much respect for my work and my opinion that (for communication between team members) I'm able to get away with language that unimportant bystanders might find objectionable. – Brendan Nov 08 '17 at 12:04
  • There is nothing worse in the world than "C++ master programmers". Writing code that is too clever for its own good is what C++ seems to be designed for. (Meanwhile I can't convince a colleague that some tiny changes would save us two thirds of all constructor and destructor calls in some time critical code). – gnasher729 Jun 01 '20 at 14:54
99

All of the modern languages I have seen may interact with C:

  • C++
  • Java
  • C#
  • Python
  • Haskell
  • Objective C
  • Rust

The need to interact with C derives from:

  • C having a simple ABI
  • C being around for a long time

It means that since those languages can communicate with C, they can:

  • leverage its libraries
  • communicate with each other through C (for example, Clang is written in C++ but offers Python Bindings hooked on its C interface).

And I would bet that all of them rely on C for their runtimes (unless they went full assembly ? dubious).

C is the Lingua Franca of the programming languages and one of the simplest (ABI-wise) not tied to a specific architecture (like assembly is), it'll take a major shift to get rid of it.

Solomon Ucko
  • 408
  • 3
  • 10
Matthieu M.
  • 14,567
  • 4
  • 44
  • 65
  • "C is the *Lingua Franca* of the programming languages"—in other words, the greatest common denominator. – Anakhand Aug 06 '20 at 15:39
  • C language is the first level above machine (assembly language). And it is at a high enough level, and anyone learning to program, can with little effort, read and follow a C program. – Leslie Satenstein Aug 12 '22 at 01:45
46

In my opinion this is a very short sighted question akin to "My friends and I listen to Reggae. Does anybody really still listen to Rap?".

Every language out there has its use. Different languages definitely have their niches. But asking about C! I am sure fewer people use C# than C on a daily basis (from the totally biased view point of working in a shop where nobody uses C#).

Quick google looking on the relative popularity of languages.
I am sure none of this is authoritative but we can use it to see trends:

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
http://langpop.com/

Even looking at SO ratio of question on tags:
https://stackoverflow.com/tags

  • C#: 209845
  • 16 other tags
  • C: 38790

So C is the 18 most popular topic on SO (and there are a lot of other languages there).

Note: The TIOBE index above has been constantly updated for over a decade (and has some data going back 3 decades) is supposed to measure engineers working in each language (though I have no idea how accurate that is). Of the top 10 languages except Java/Visual Basic it reflects what people in my shop know (though our ratios will be slightly different as we have a much smaller sample size).

Martin York
  • 11,150
  • 2
  • 42
  • 70
  • 2
    This answer confuses me...you go on about C# and then show SO question tags but none of that has anything really do to with C being used. Popularity (especially on langpop, where they use search engine queries to determine popularity) doesn't really show the modern day usage of a language, just modern day searches on a language. You must take into account, for searches, that C is used frequently in Universities for the lower level classes so that can increase the number of queries and also SO posts. – Jetti Aug 26 '11 at 14:58
  • 3
    @Jetti: Thats why I explicitly say: `I am sure none of this is authoritative but we can use it to see trends` But I disagree with your second statement; C is no longer the major language taught at institutes of higher learning (if it was then the new batch of graduates would not be as useless). People tend to be learning Java/C# sharp nowadays. Also the Tiobe report is about jobs not queries. – Martin York Aug 26 '11 at 16:57
  • Looking back, there seems to be a poor word choice on my part. I didn't mean the low number classes (beginning classes), I meant the systems classes (computer architecture) is where C is used. – Jetti Aug 26 '11 at 17:48
  • 4
    SO tag count does not define language popularity in general, it simply shows language popularity between *users of SO*. – Ed S. Aug 26 '11 at 19:42
  • 4
    @Ed S. Obviously. But the question is not about popularity. Its about the existence of C as a language. The SO tag count shows us that it is definitely not a dead language. The fact that C is in the top 2 on the other sites does not make it the first/second most used language. But its existence in the top 10 is a significant marker that it is not dead. Of course none of this is proof just strong indicators that C is still being actively used. – Martin York Aug 26 '11 at 21:32
  • @Ed S - perhaps this shows that C# users understand their language less, and therefore have to ask more questions ;-) On the other hand, I am not quite sure what to make of the attitude of the OP - who seems to suggest that only Windows APIs are going to be developed in future, using Microsoft's borked C-hack. But in the real world, most embedded systems are non-Windows and C is very much a live language. – Andrew Sep 07 '12 at 04:26
  • @LokiAstari +1 (I wanted to give +100) for the Rap thing lolz :). But you are right as well. I wonder what you make out of [this](http://programmers.stackexchange.com/questions/203024/why-not-have-a-high-level-language-based-os-are-low-level-languages-more-effici) – ha9u63a7 Jun 28 '13 at 11:17
  • @LokiAstari I think it depends what department you are in... my CS friends love their Java and know little, if any, C (in fact, one of them told me the "volatile" keyword didn't do anything useful). In the Computer Engineering department, however, it's our bread and butter language. – mgw854 Jan 20 '14 at 22:40
23

You may need to use C when you are low on resources and don't need object oriented capabilities.

Many softwares in use today are still written in C, not to mention hardware drivers.

According to Tiobe index, C is still the most used language.


As tcrosley suggested, you may want to take a look at this related question.


You should also check for some related articles on the differences between C and C++, like this wiki or this for example.

Jose Faeti
  • 2,815
  • 2
  • 23
  • 30
  • 4
    ahem !! thats a great point. I never gave a thought that "OOP capabilities actually add overhead for the language". Thanks for making this valid point clear. Now, i can understand, where C is ahead of others – Pankaj Upadhyay Aug 26 '11 at 12:54
  • 1
    Yes that's something you should consider when your program doesn't require particular OOP capabilities, it's just a waste and may be not as fast as a plain C implementation. – Jose Faeti Aug 26 '11 at 12:57
  • 7
    @Pankaj C++ generally doesn't necessarily add much run time overhead, a lot of the complexity of the language is the principle of "not paying for what you don't use" - if you don't use exceptions then exceptions don't slow down or add size to your code. The compiler is larger and more complex though – Martin Beckett Aug 26 '11 at 15:27
  • 2
    re C in the embedded field, see also this question and answers: http://programmers.stackexchange.com/questions/84514/why-does-c-dominate-in-the-embedded-software-market/ – tcrosley Aug 26 '11 at 17:00
  • 7
    You never actually *need* OOP capabilities, it simply works well in some scenarios. – Ed S. Aug 26 '11 at 19:41
  • @Ed S.: Sure, go tell this to your boss and listen to what he has to say :) – Jose Faeti Aug 29 '11 at 08:50
  • 2
    @Jose Faeti: My boss would agree because my boss is an experienced, rational guy. He doesn't buy into programming religion. – Ed S. Aug 29 '11 at 16:54
  • 1
    I cringe every time someone equals C++ with OO. `-1` from me just for that. – sbi Mar 04 '13 at 13:46
  • 1
    @sbi I didn't state C++ is a OOP language (nor do I equal it with OO), but that it offers OOP capabilities. How many of them to be considered a fully OOP language I don't know and that's not the point at all I believe. – Jose Faeti Mar 07 '13 at 09:03
  • 1
    _"You may need to use C when you are low on resources and don't need object oriented capabilities."_ What if I need generic programming capabilities? Functional ones? C++ is a multi-paradigm language. It shines brightest and is most powerful when paradigms are elegantly combined. (Note: `std::vector>` does just that.) – sbi Mar 07 '13 at 15:51
20

It sounds like you are trying to convince yourself that C is useless and therefore can be ignored. Let's break your question down:

"I figured that someone would only learn C for testing only if there is development done in C."

No, there are many reasons to learn C. Even if you didn't know that I would still avoid using blanket statements like that, especially in conjunction with circular logic. Obviously one needs to know the language the code is written in to be able to properly test/fix it but that assumes that the langauge is still used as a given and is true for any language and not just C.

"In my knowledge, all the development related to COM and hardware design are also done in C++."

That is incorrect.

"Therefore, learning C doesn't make sense if you need to use C++. I also don't believe in historic significance, so why waste time and money in learning C?"

This is the most questionable logic of all. First of all, historic significance is something you should believe in, because if you did you'd know that C is a subset of C++ and, because of that, knowing C can help you be a better C++ programmer. Of course, C was also influential to most languages that came after it so the benefits don't stop there. In addition, because C is so important it can not be considered as having only historical significance. It is still widely used and thus cannot be relegated to a secondary position like that. You can argue that it's not a language that every programmer needs to use and have a thorough knowledge of and that would be right but please don't build your argument on saying that you don't believe something without examining its true merits first.

GonzoKnight
  • 109
  • 3
  • 7
    ***C is a subset of C++*** , Is that what you meant ?? . C is not a Subset of C++; infact they are pretty different. Yes, C++ is an enhancement of C, or sometimes referred as ***C with classes and OOP***, but to say C is a subset, doesn't justify – Pankaj Upadhyay Aug 31 '11 at 05:37
  • 8
    C++ is mostly a superset of an _old version_ of C, and C's gone in a somewhat different direction since then. Some aspects of the languages have gone in largely parallel directions, but others have not (and C++ has a _lot_ of other things besides). – Donal Fellows May 26 '12 at 14:22
  • I agree in voting for clarification of that fact, not all valid C programs are valid C++ programs, i.e. C++ is not a superset of C. However, it is a superset of how C was at the point of making the decision for it to be a superset, as Donal Fellows mentioned. It simply doesn't make sense to say that it is anymore, when it's no longer true however. – Joshua Hedges May 25 '17 at 19:18
  • Similarly: Almost nobody actively speaks Latin these days (except in the Vatican) but knowing Latin immensely boosts your understanding of a multitude of other languages. – Lagerbaer May 27 '20 at 03:31
  • @Lagerbaer It is used in the scientific community a lot :0 You would be suprised... :) – Yunfei Chen Feb 21 '21 at 22:24
16

In addition to embedded systems, most newer languages have some way to interface with C. When writing a library that you want to have an easy time using in all of those languages, C is an obvious choice. C++, while it can also interface with some languages (such as Python (CPython only)), C++ cannot interface with a greater number of languages due to some of its features (name mangling especially, but templates don't help the issue). The C ABI is one of the easiest to interface with (I know you can write C++ and use extern "C" for the interface. I don't care).

It also has the benefit that C and C++ are really the best languages for systems programming and the C compile times are much faster. C++ compile times are noticeably the worst of any language I've used.

Now while there are other languages that want to become the popular systems language out there (I know about D in particular), a far majority of software is written in C/C++. Languages like D require someone to create a wrapper around the C library instead of just using it directly (like you would from C++).

jsternberg
  • 1,531
  • 11
  • 15
  • D can call C code directly, just like C++. All you need if the function prototype (again, just like C++). You just write `extern(C)` in D, whereas in C++ you write `extern "C"` – Peter Alexander Aug 27 '11 at 12:29
  • @Peter Alexander I'm aware of extern(C) in D. That's what I was referring to when I said wrapper file. You cannot directly include the C header (which you can do in C++, assuming the C header uses extern "C" and has the #ifdef __cplusplus blocks, which most do). There are then other incompatibilities among just using extern(C) (particularly how strings are handled. To my knowledge, they do not have a null terminator in D. So you have to specially change the array when passing it to C). – jsternberg Aug 27 '11 at 13:12
6

Well I think C is the most powerful language Due to the following reasons!

1) AT first C , It's a systems language (which means it can be used to do low-level programming with minimal or no run-time).

2) Speed of the resulting application. C source code can be optimized much more than higher-level languages because the language set is relatively small and very efficient. It is about as close as you can get to programming in assembly language, without programming in assembly language. and you can even use assembly and C together!

3) C has which is its application in Firmware programming (hardware). That is due to its ability to use/work with assembly and communicate directly with controllers, processors and other devices.

4) C is a building block for many other currently known languages. Look up the history of C and you will find that it has been around for some time (as programming languages go anyway). Take a look at Python for example a fully Object-Oriented High-Level programming language. It is written in C (perhaps C++ too). That tells you if you ever want to know what is going on under the hood in other languages; understanding C and how it works is essential.

An applications language is used for high-level programming, e.g. writing a word processor or game. Examples of applications languages are Java, C#. The reason is because they contain garbage collection, automatic typing, run-time validation, etc. - where the focus is productivity.

A systems language is used for low-level programming. e.g. A micro-controller, a driver, and OS kernel. Examples include assembly, C. They require little or no runtime to run code directly on the hardware, and the focus is for the programmer to have direct control over the hardware.

Overall, it's declining as an applications language, but still holding strong as a systems language.

niko
  • 2,119
  • 3
  • 22
  • 19
2

Oh yes, it is used. I work in the field of network packet processing. I have been at two different companies where we process network packets. So, we are operating at the Ethernet or IP level, not at the level above TCP.

Interestingly, in both companies C was chosen over C++. In one of the companies, one of the two products was built on top of Linux kernel, whereas the other product was built in Linux userspace. The kernel product obviously used C as Linux kernel is programmed in C, but they chose to use C for the userspace product as well. Both products were developed starting from about year 2000 (the kernel product a bit before 2000 and the userspace product a bit after 2000).

In the company where I went after that, the product was built on C, not on C++. It is actually a continuation of a project from the mid-1990s, although due to recent performance improvement demands, it was decided that essentially everything will be rewritten. We had an option to select C++ due to this rewrite, but didn't do so.

In the field of network packet processing, performance counts a lot. So, I want to implement my own hash table having higher performance than existing hash tables. I, not the hash table author, am who selects what hash function is to be used. Perhaps I want performance and go for MurMurHash3. Perhaps I want security and go for SipHash. Memory allocators are obviously custom. In fact, all the important data structures we use have been custom-implemented for the highest possible performance.

While there is nothing that would prevent the use of C++, it is usually a bad idea. A single thrown exception per packet will drop the packet processing rate to unacceptable levels! So, we cannot use C++'s exceptions. Way too slow. We are already using kind-of object-oriented C code by implementing data structures as structs and then implementing functions operating on those structs. C++ would allow having virtual functions, but then again virtual function calls would kill performance if used everywhere. So, it's better to be explicit and have a function pointer if virtual function calls are needed.

C++ will do a lot of things behind your back: memory allocation, etc. On the other hand, in C that usually doesn't happen. You can write a function that allocates memory, but usually it is apparent from the interface of the function that allocation is happening.

As example of the kind of micro-optimizations that you can do when programming in C, take a look at the container_of macro in the Linux kernel. Sure, you could use container_of in C++ code, but who does that? I mean, it is entirely acceptable in most C programs, but typical C++ programmers would immediately propose something else, such as a linked list that allocates the link nodes as separate blocks. We don't want that because every allocated memory block is bad for performance.

Perhaps the only thing that would benefit us in C++ is that C++ allows template metaprogramming, meaning you can sometimes avoid virtual function calls while still having a function parameter, and allow the compiler to inline the functions. But template metaprogramming is complicated, and we have managed to fulfill all requirements in C, so the benefit of this feature in C++ is not so critical.

In one of the companies, we actually had a custom compiled language where part of the features were implemented in. Guess which was the target language of the compiler? Assembly? No, we had to support both 32-bit and 64-bit architectures. C++? Surely you jest. Obviously, it was C with GCC's computed goto. So, the custom language was compiled to C (or actually the gcc variant of C that supported computed goto), and the C compiler produced assembly.

juhist
  • 2,579
  • 10
  • 14
2

C Language was born in 1972 it's 48 years old, C++ was born in 1985, so it's 35 years old, they have 13 years difference: It's incredible to realise how much more C has achieved as a language in comparison to C++ but also to a lot of other languages, I don't believe its just due to those 13 years difference.

C is elegant, easy and extremely powerful; the first thing that motivated me to use it was the closeness with assembly language: those 32 keywords could almost be directly translated into machine code, and the freedom in using memory allocation and pointers was in par with those years computing: you could do anything with C

Is C better than C++ then? I have no idea, comparing two programming languages is a critical task, you need to take into account the field, the application and when you compare them: what I believe is that there is still going to be a reason in the future to teach C in a computing course, I don't believe the same for other languages that are more application based: C is sort of the Math of computing IMHO.

Edoardo
  • 236
  • 1
  • 7
1

"Here's a thought ..." (in fact, it's exactly the "thought" that the language's original designers had in mind:

"C" is much better than Assembler!"

"The Linux® Operating System" supports more than 20 different hardware platforms – "and this is why." Because the only difference needs to be in the /arch directory ... and the boot-time "trampoline" code. All of the source code that does not have to be "architecture-specific" ... isn't. Instead, the system assumes the presence of a language-compiler – most often but not necessarily gcc – which supports the target.

"C" is intended to be a language which directly supports "low-level constructs," and whose source-code can be predictably associated with them. So, the Linux® developers could "code very close to the metal," as of course they must, while calling-out to architecture-specific (assembly-language) subroutines only when they must.

Incidentally, this was quite an advanced concept, at the time. All operating systems prior to Unix® were written in assembler. The "C" programming language was originally conceived as a tool for writing Unix.®

Today: "the uber-cool language 'X' ... is written in ..."

Mike Robinson
  • 1,765
  • 4
  • 10
0

I still use C on a daily basis and one of the primary reasons is because of interop with other languages and an SDK designed to be used by plugins built by all kinds of compilers in various languages.

I can't write a C++ API that uses classes with constructors and destructors and vtables, function overloading, throws exceptions, etc. that can be used from Lua, C#, Python, C, etc. let alone a C++ plugin written using different compilers and settings from our own.

I can't write a C# SDK that can be called from Python, e.g., or a Python SDK that can be called from C#.

C is the only language here that allows me to create an API that can be called from any of these languages. That said I often use C++ to implement these C interfaces (though I sometimes just implement them in C).

Besides that, I sometimes find C the easiest language to work with for things like low-level data structures and memory allocators. All the extra type safety you gain in C++ doesn't help if you're writing a memory allocator designed to pool aligned bits and bytes. And against C++'s rich type system and exception-handling, it's not easy to roll your own data structures -- just look at how much effort it takes to write a data structure as trivial as std::vector if you want to make it exception-safe and avoid invoking ctors and dtors on elements you didn't insert to the container (I'm speaking as one who has implemented the entire C++ standard library). When just a growable array is very difficult to implement well, then imagine the work required to implement a production-quality BVH.

I prefer C++ over C when I want to use existing data structures or implement higher-level ones by using existing ones, but if I'm going to be implementing a low-level data structure at the core of an engine that has no use for existing data structures, C definitely makes that a lot easier to do with its uber simplistic type system that lets you just memcpy things here and memmove things there, malloc a contiguous block and realloc it there, without worrying about constructors, destructors, and exceptions being thrown.