Author Topic: How many people code in C these days, and if so, why?  (Read 48746 times)

0 Members and 1 Guest are viewing this topic.

Online IanBTopic starter

  • Super Contributor
  • ***
  • Posts: 12392
  • Country: us
How many people code in C these days, and if so, why?
« on: May 03, 2020, 03:42:33 pm »
I think the last time I wrote any code for a C compiler was about 20 years ago. Since then, using C++ has just been more convenient. After using C++, C just seems too painful and restrictive.

There are often coding discussions here, where people seem to be  talking about "C", but I'm not sure if everyone is being precise in their language, or if they may actually be using a C++ compiler? For instance, Visual Studio technically has a C compiler, but it is somewhat hidden and you have to take special steps to invoke it.

If you do write in C these days, what is the reason? Is it because there is no C++ compiler for your target hardware, or are there special advantages to C that make you prefer it?
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: How many people code in C these days, and if so, why?
« Reply #1 on: May 03, 2020, 03:58:33 pm »
This thread should be locked. NOW.
 
The following users thanked this post: Dave, Bassman59, mark03, Warhawk, blueskull, Ian.M, Koen, newbrain, NivagSwerdna, BBBbbb, bsudbrink, Jacon

Offline Warhawk

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: 00
    • Personal resume
Re: How many people code in C these days, and if so, why?
« Reply #2 on: May 03, 2020, 04:03:30 pm »
I think the last time I wrote any code for a C compiler was about 20 years ago. Since then, using C++ has just been more convenient. After using C++, C just seems too painful and restrictive.

There are often coding discussions here, where people seem to be  talking about "C", but I'm not sure if everyone is being precise in their language, or if they may actually be using a C++ compiler? For instance, Visual Studio technically has a C compiler, but it is somewhat hidden and you have to take special steps to invoke it.

If you do write in C these days, what is the reason? Is it because there is no C++ compiler for your target hardware, or are there special advantages to C that make you prefer it?

Code what? I've been in the industry for more than 10 years and have never seen anything else but C (with small exceptions such as ASM and C++) for embedded applications. And I am talking about quite big projects for industrial automation and automotive. In my opinion, C offers a good balance between portability, readability, comfort, and the level of abstraction between the hardware and software. More sophisticated language, higher the level of abstraction, and less control of the hardware. This is a big deal for realtime applications. I like that I can open the ASM listing and C side-by-side and see how my code works.
So my two cents - C for embedded, Python for "getting things done".

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2267
  • Country: 00
Re: How many people code in C these days, and if so, why?
« Reply #3 on: May 03, 2020, 04:06:25 pm »
I find C++ a horrible language, so I use plain C most of the time.

For GUI development I use Qt which is a C++ framework. This requires to use C++ and classes.
But I only write the bare minimum of C++, necessary to use Qt.

Fortunately you can write pure C code in .cpp files and it will compile fine (most of the time!).
Also, many modules that have nothing to do with the GUI, are in plain C and contain lines like:

Code: [Select]
#ifdef __cplusplus
extern "C" {
#endif

This way I can write real plain C code also in Qt (C++) projects.
 
The following users thanked this post: neil555, rgarito

Offline maginnovision

  • Super Contributor
  • ***
  • Posts: 1966
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #4 on: May 03, 2020, 04:10:33 pm »
I mostly use C++ because it's easier and cleaner to get some things done. I use C a lot for some smaller projects and projects where C++ is really not an option. One processor I work with the linker chokes on C++ generated intermediate files constantly so it's basically not allowed unless you want to figure out which parts of the C++ code it didn't like.
 

Offline Warhawk

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: 00
    • Personal resume
Re: How many people code in C these days, and if so, why?
« Reply #5 on: May 03, 2020, 04:18:02 pm »
I find C++ a horrible language, so I use plain C most of the time.

For GUI development I use Qt which is a C++ framework. This requires to use C++ and classes.
But I only write the bare minimum of C++, necessary to use Qt.

Fortunately you can write pure C code in .cpp files and it will compile fine (most of the time!).
Also, many modules that have nothing to do with the GUI, are in plain C and contain lines like:

Code: [Select]
#ifdef __cplusplus
extern "C" {
#endif

This way I can write real plain C code also in Qt (C++) projects.

Karel, In my opinion you combined the worst from both worlds. I used to have a colleague who programmed everything in ASM. His C files were #asm #endasm directives everywhere. A nice gentleman but I had to let him go. Nobody understood his work.

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2267
  • Country: 00
Re: How many people code in C these days, and if so, why?
« Reply #6 on: May 03, 2020, 04:38:50 pm »
I find C++ a horrible language, so I use plain C most of the time.

For GUI development I use Qt which is a C++ framework. This requires to use C++ and classes.
But I only write the bare minimum of C++, necessary to use Qt.

Fortunately you can write pure C code in .cpp files and it will compile fine (most of the time!).
Also, many modules that have nothing to do with the GUI, are in plain C and contain lines like:

Code: [Select]
#ifdef __cplusplus
extern "C" {
#endif

This way I can write real plain C code also in Qt (C++) projects.

Karel, In my opinion you combined the worst from both worlds. I used to have a colleague who programmed everything in ASM. His C files were #asm #endasm directives everywhere. A nice gentleman but I had to let him go. Nobody understood his work.

I have never been out of a job and caring about your opinion is very low on my priority list.

Maybe I was a bit rude. I apologize.
« Last Edit: May 03, 2020, 07:34:49 pm by Karel »
 
The following users thanked this post: Warhawk

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: How many people code in C these days, and if so, why?
« Reply #7 on: May 03, 2020, 04:43:11 pm »
I use C in projects that are targeted for smaller processors with limited RAM/code space and/or no C++ compiler [with decent price or code quality] is available for the given processor. For the projects with more target processor resources available and support for at least C++11, I prefer [a small subset of] C++. Said that, I am now using C in the current project due to the fact that the project team is more comfortable with using C instead of C++.

Ps. I also check quite often the assembly code generated by the compiler so that I do not write anything stupid which would bloat my code.
« Last Edit: May 03, 2020, 04:49:27 pm by Kalvin »
 

Online coppice

  • Super Contributor
  • ***
  • Posts: 9521
  • Country: gb
Re: How many people code in C these days, and if so, why?
« Reply #8 on: May 03, 2020, 04:48:20 pm »
I think the last time I wrote any code for a C compiler was about 20 years ago. Since then, using C++ has just been more convenient. After using C++, C just seems too painful and restrictive.

There are often coding discussions here, where people seem to be  talking about "C", but I'm not sure if everyone is being precise in their language, or if they may actually be using a C++ compiler? For instance, Visual Studio technically has a C compiler, but it is somewhat hidden and you have to take special steps to invoke it.

If you do write in C these days, what is the reason? Is it because there is no C++ compiler for your target hardware, or are there special advantages to C that make you prefer it?
I think the last time I wrote any code for a C++ compiler was about 23 years ago. Using C has always been more convenient. After using C, C++ just seems too painful and restrictive.

There are often coding discussions here, where people seem to be  talking about "C++", but I'm not sure if everyone is being precise in their language, or if they may actually writing C, and just compiling it using a C++ compiler? For instance, Visual Studio technically has a C++ compiler, but many of us use it to compile the same C source code files we compile with GCC, IAR and other C compilers.

If you do write in C++ these days, what is the reason? Is it because there is no C compiler for your target hardware, or are there special advantages to C++ that make you prefer it?
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15397
  • Country: fr
Re: How many people code in C these days, and if so, why?
« Reply #9 on: May 03, 2020, 04:50:20 pm »
I also mostly use C, and also consider C++ a monster with too many quirks.

C compilers are virtually available for any target, are robust.

I mostly do embedded dev these days though as far as programming goes, and otherwise a few command-line tools. I used to write GUI apps in C in the past, very rarely these days, although I have written a cross-platform GUI library in C based on OpenGL which allows to write cross-platform GUI apps in C in a decent way. Not too shabby but I wouldn't want to spend my whole time doing this anyway.

My use of C is pretty object-oriented though (at least in the base concepts of OO), and with C properly used and mastered, I've never really found C++ to add much convenience for that overall. Of course, YMMV a lot.

C++ is too complex IMHO, and promotes a kind of OO programming that can yield monster code bases that can be very hard to evolve. Badly used inheritance, for example, can make your life a hell in the long run. Of course this is not specific to C++, it's common with many OO languages that support multiple inheritance. Another pitfall with C++ is that in practice, it's a very "fragmented" language, because it's so complex that most developers tend to use their own subset. Lastly, C++ compilation times are much longer than C compilation times, which granted is not that important, but that's an additional benefit of using C in my eyes.


 
The following users thanked this post: Siwastaja

Online IanBTopic starter

  • Super Contributor
  • ***
  • Posts: 12392
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #10 on: May 03, 2020, 04:54:21 pm »
I find C++ a horrible language, so I use plain C most of the time.

Quote
Fortunately you can write pure C code in .cpp files and it will compile fine (most of the time!).

These two statements are in contradiction to each other. If your source file has a .cpp extension you are invoking the C++ compiler and complying with the C++ language standards.

So we can put you in the group of people who use C++, even if you are restricting yourself to a subset of the language.
 

Online coppice

  • Super Contributor
  • ***
  • Posts: 9521
  • Country: gb
Re: How many people code in C these days, and if so, why?
« Reply #11 on: May 03, 2020, 04:58:59 pm »
I find C++ a horrible language, so I use plain C most of the time.

Quote
Fortunately you can write pure C code in .cpp files and it will compile fine (most of the time!).

These two statements are in contradiction to each other. If your source file has a .cpp extension you are invoking the C++ compiler and complying with the C++ language standards.

So we can put you in the group of people who use C++, even if you are restricting yourself to a subset of the language.
If that's the kind of logic you use, you could have a great career as a religious apologist.
 
The following users thanked this post: Sal Ammoniac, Jacon

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2267
  • Country: 00
Re: How many people code in C these days, and if so, why?
« Reply #12 on: May 03, 2020, 04:59:53 pm »
I find C++ a horrible language, so I use plain C most of the time.

Quote
Fortunately you can write pure C code in .cpp files and it will compile fine (most of the time!).

These two statements are in contradiction to each other. If your source file has a .cpp extension you are invoking the C++ compiler and complying with the C++ language standards.

So we can put you in the group of people who use C++, even if you are restricting yourself to a subset of the language.

Formally you are correct, I use both C and C++.
 

Online IanBTopic starter

  • Super Contributor
  • ***
  • Posts: 12392
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #13 on: May 03, 2020, 05:00:33 pm »
I sense (as I expected) that C is used for embedded work on low level hardware.

However, C++ offers a vast toolkit of features to choose from, and you are not obligated to use them all. You can restrict yourself to a small subset and still have a more comfortable time while writing compact, efficient and transparent code.

Anyway, I got my answer. Many people are writing in C these days, and [in this forum] it is [mainly, it seems] for embedded applications.
« Last Edit: May 03, 2020, 05:08:54 pm by IanB »
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23096
  • Country: gb
Re: How many people code in C these days, and if so, why?
« Reply #14 on: May 03, 2020, 05:02:34 pm »
I still write stuff in C. In fact I'm just working through fixing 20 years of pain in a 95KLOC C program. Why do I still use it:

1. Knowledge is retained and valuable for 30 years now. That was a good investment as it allows you to get really good at the language.
2. The toolchains available are mature, light weight and reliable.
3. Relative simplicity allows compilers to make excellent optimisations.
4. It's small enough to fit in your head.
5. It works the same on everything from embedded to desktop applications.
6. It's low enough level to be used for system programming and with abstractions high enough to build high level applications with.
7. It's damn fast.
8. It allows you to decide where your performance tradeoffs are made.
9. Intent can be clearly expressed.

The above program discussed has been rewritten twice so far. One talented individual rewrote it in C++ using templates and boost. It never worked and was too difficult to extend. It was also 20% slower. Someone came along and thought hey lets do it in C#. Nope! Better than C++ but still too slow (70% slower creating objects galore) and eats 400Gb (yes 400Gb) of memory. I'm sure someone will come along and suggest Rust soon and blow a lot of money unsuccessfully rewriting it again.

For now I'll look objectively at each problem and invest in that 30 year knowledge in that 20 year old codebase. Which is older than Rust, older than C# and older than a version of C++ that even begins to make sense.

For ref this is a high level matching engine, not a system program and not embedded. It reads a DSL and reference data from disk into memory and then streams about 100 megabits of traffic in peak (per process), matches, tags and routes it. It has had uptimes of over three years for a single process historically speaking.

The only problems are is it's an unsafe language, which is solved mostly using your brain a bit longer, then Valgrind and Coverity...

Edit: I will not this is not my day job. I'm doing this because it's fun and accidentally getting paid for it on the side. My day job is running entirely the opposite of this and dealing with the several order of magnitude more pain.
« Last Edit: May 03, 2020, 05:08:29 pm by bd139 »
 
The following users thanked this post: Jacon

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2267
  • Country: 00
Re: How many people code in C these days, and if so, why?
« Reply #15 on: May 03, 2020, 05:03:44 pm »
I sense (as I expected) that C is used for embedded work on low level hardware.

However, C++ offers a vast toolkit of features to choose from, and you are not obligated to use them all. You can restrict yourself to a small subset and still have a more comfortable time while writing compact, efficient and transparent code.

Anyway, I got my answer. Many people are writing in C these days, and it is for embedded applications.

Maybe I'm an exception but all non-GUI software I write for the pc is written in C using gcc, not g++!
 

Online coppice

  • Super Contributor
  • ***
  • Posts: 9521
  • Country: gb
Re: How many people code in C these days, and if so, why?
« Reply #16 on: May 03, 2020, 05:06:57 pm »
Anyway, I got my answer. Many people are writing in C these days, and it is for embedded applications.
C is still used heavily for server, and HPC applications, as well as embedded.
 

Online IanBTopic starter

  • Super Contributor
  • ***
  • Posts: 12392
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #17 on: May 03, 2020, 05:07:43 pm »
If that's the kind of logic you use, you could have a great career as a religious apologist.

 ;D

Religion is about vague, unprovable assertions.

Technology is about facts.

It is a fact that some things that will be accepted by a C compiler will be rejected by a C++ compiler, and vice versa. So if you compile "C" with a C++ compiler, there is no guarantee that your code will be accepted by a C compiler. The standards are different.

Maybe I'm an exception but all non-GUI software I write for the pc is written in C using gcc, not g++!

If you invoke gcc on a file with .cpp extension it will use the C++ compiler unless you force it to do otherwise. Similarly, if you invoke gcc on a file with a .c extension, then it will use the C compiler by default. So if your files have a .c extension, then I will agree that you are using C.
 

Online IanBTopic starter

  • Super Contributor
  • ***
  • Posts: 12392
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #18 on: May 03, 2020, 05:09:40 pm »
C is still used heavily for server, and HPC applications, as well as embedded.

Interesting. Post edited.
 

Offline engrguy42

  • Frequent Contributor
  • **
  • Posts: 656
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #19 on: May 03, 2020, 05:10:58 pm »
Different tools for different tasks. For me, C# is great for UI-based stuff. C++ comparatively sucks for that, but is great for graphics API stuff (DirectX, OpenGL, etc.). And C is great for lower level hardware stuff.

I suppose the best software developers learn ALL the tools and use the best one for the job, rather than sticking with one and getting offended when anyone disagrees.

Geez guys.
- The best engineers know enough to realize they don't know nuthin'...
- Those who agree with you can do no wrong. Those who disagree can do no right.
- I'm always amazed at how many people "already knew that" after you explain it to them in detail...
 
The following users thanked this post: m98

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2267
  • Country: 00
Re: How many people code in C these days, and if so, why?
« Reply #20 on: May 03, 2020, 05:17:13 pm »
Maybe I'm an exception but all non-GUI software I write for the pc is written in C using gcc, not g++!

If you invoke gcc on a file with .cpp extension it will use the C++ compiler unless you force it to do otherwise. Similarly, if you invoke gcc on a file with a .c extension, then it will use the C compiler by default. So if your files have a .c extension, then I will agree that you are using C.


Yes, my files have .c extensions.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9935
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #21 on: May 03, 2020, 05:39:22 pm »
How many of the advanced features of C++ are used in the Linux operating system?  I don't know the answer but I think it is zero.  Linux is written in C.  I'm pretty sure Windows is as well.  Both are really huge code bases but somehow it all works out.

I have spent about 20 years trying to build up any enthusiasm for C++ and I just can't get there.  I'm just too old to learn C++ and, since I'm not trying to cure world hunger, I don't see any reason to bother.  Most of my work is in the embedded space and C++ doesn't bring much to the dance.

I'll stick with Fortran and C while the world moves on.
 

Offline engrguy42

  • Frequent Contributor
  • **
  • Posts: 656
  • Country: us
Re: How many people code in C these days, and if so, why?
« Reply #22 on: May 03, 2020, 05:45:28 pm »

I have spent about 20 years trying to build up any enthusiasm for C++ and I just can't get there. 


I hear ya...but if you want a lot of fun try writing a ray tracer for 3D graphics.  :-+

It's a ton of fun, and C++ is almost mandatory. Although I think C and C++ are pretty much interchangeable with those graphics API's.

And then tie that into a C# interface and GUI.  :-+

And yeah, I have lots of fond memories of Fortran  :D

Are there still compilers available for that?? Hmm.......
« Last Edit: May 03, 2020, 05:47:17 pm by engrguy42 »
- The best engineers know enough to realize they don't know nuthin'...
- Those who agree with you can do no wrong. Those who disagree can do no right.
- I'm always amazed at how many people "already knew that" after you explain it to them in detail...
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28050
  • Country: nl
    • NCT Developments
Re: How many people code in C these days, and if so, why?
« Reply #23 on: May 03, 2020, 05:49:55 pm »
If you do write in C these days, what is the reason? Is it because there is no C++ compiler for your target hardware, or are there special advantages to C that make you prefer it?
I code a lot in C. Mostly on microcontrollers and projects which where written in C. If I have a chance I like to use C++. Using objects makes for cleaner interfaces (like having functions with default arguments and the same functions with different parameters) and I like that I can avoid pointers in C++. And then there is the STL library which has many useful features. I'm not saying C++ is perfect for everything. I use Lua as well and likely Python will be added at some point.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6576
  • Country: nl
Re: How many people code in C these days, and if so, why?
« Reply #24 on: May 03, 2020, 05:52:15 pm »
If you do write in C these days, what is the reason? Is it because there is no C++ compiler for your target hardware, or are there special advantages to C that make you prefer it?
I graduated in the 90s became an EE , since then had 12 SW jobs with 5 companies and I solely have written C and now for the testing some Python.
First companies the target was 64kB upto 1MB with 100-200klocs
Last company is 650+MB code, est. 300+Mlocs and growing, I luckily only work wit 20Mlocs of that, and still everything except the unittests and other tests is in C.

Why? Because the companies use it and want it and it still is the defacto standard for serious industrial machines and real time hardware. If you program GUIs or games or internet stores, websites etc. choose something more appropriate for that.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf