After All These Years, the World is Still Powered by C Programming



Many of the C projects that exist today were started decades ago.

The UNIX operating system’s development started in 1969, and its code was rewritten in C in 1972. The C language was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code.


Oracle database development started in 1977, and its code was rewritten from assembly to C in 1983. It became one of the most popular databases in the world.


In 1985 Windows 1.0 was released. Although Windows source code is not publicly available, it’s been stated that its kernel is mostly written in C, with some parts in assembly. Linux kernel development started in 1991, and it is also written in C. The next year, it was released under the GNU license and was used as part of the GNU Operating System. The GNU operating system itself was started using C and Lisp programming languages, so many of its components are written in C.


But C programming isn’t limited to projects that started decades ago, when there weren’t as many programming languages as today. Many C projects are still started today; there are some good reasons for that.


How is the World Powered by C?

Despite the prevalence of higher-level languages, C continues to empower the world. The following are some of the systems that are used by millions and are programmed in the C language.


Microsoft Windows

Microsoft’s Windows kernel is developed mostly in C, with some parts in assembly language. For decades, the world’s most used operating system, with about 90 percent of the market share, has been powered by a kernel written in C.

Linux

Linux is also written mostly in C, with some parts in assembly. About 97 percent of the world’s 500 most powerful supercomputers run the Linux kernel. It is also used in many personal computers.


Mac

Mac computers are also powered by C, since the OS X kernel is written mostly in C. Every program and driver in a Mac, as in Windows and Linux computers, is running on a C-powered kernel.


Mobile

iOS, Android and Windows Phone kernels are also written in C. They are just mobile adaptations of existing Mac OS, Linux and Windows kernels. So smartphones you use every day are running on a C kernel.


OS Kernels Written in C

Databases

The world’s most popular databases, including Oracle Database, MySQL, MS SQL Server, and PostgreSQL, are coded in C (the first three of them actually both in C and C++).


Databases are used in all kind of systems: financial, government, media, entertainment, telecommunications, health, education, retail, social networks, web, and the like.

Database Powered by C

3D Movies

3D movies are created with applications that are generally written in C and C++. Those applications need to be very efficient and fast, since they handle a huge amount of data and do many calculations per second. The more efficient they are, the less time it takes for the artists and animators to generate the movie shots, and the more money the company saves.


Embedded Systems

Imagine that you wake up one day and go shopping. The alarm clock that wakes you up is likely programmed in C. Then you use your microwave or coffee maker to make your breakfast. They are also embedded systems and therefore are probably programmed in C. You turn on your TV or radio while you eat your breakfast. Those are also embedded systems, powered by C. When you open your garage door with the remote control you are also using an embedded system that is most likely programmed in C.


Then you get into your car. If it has the following features, also programmed in C:

  • automatic transmission
  • tire pressure detection systems
  • sensors (oxygen, temperature, oil level, etc.)
  • memory for seats and mirror settings.
  • dashboard display
  • anti-lock brakes
  • automatic stability control
  • cruise control
  • climate control
  • child-proof locks
  • keyless entry
  • heated seats
  • airbag control

You get to the store, park your car and go to a vending machine to get a soda. What language did they use to program this vending machine? Probably C. Then you buy something at the store. The cash register is also programmed in C. And when you pay with your credit card? You guessed it: the credit card reader is, again, likely programmed in C.


All those devices are embedded systems. They are like small computers that have a microcontroller/microprocessor inside that is running a program, also called firmware, on embedded devices. That program must detect key presses and act accordingly, and also display information to the user. For example, the alarm clock must interact with the user, detecting what button the user is pressing and, sometimes, how long it is being pressed, and program the device accordingly, all while displaying to the user the relevant information. The anti-lock brake system of the car, for example, must be able to detect sudden locking of the tires and act to release the pressure on the brakes for a small period of time, unlocking them, and thereby preventing uncontrolled skidding. All those calculations are done by a programmed embedded system.


Although the programming language used on embedded systems can vary from brand to brand, they are most commonly programmed in the C language, due to the language’s features of flexibility, efficiency, performance, and closeness to the hardware.

Many Embedded Systems Run on C


Why is the C Programming Language Still Used?

There are many programming languages, today, that allow developers to be more productive than with C for different kinds of projects. There are higher level languages that provide much larger built-in libraries that simplify working with JSON, XML, UI, web pages, client requests, database connections, media manipulation, and so on.


But despite that, there are plenty of reasons to believe that C programming will remain active for a long time.


In programming languages one size does not fit all. Here are some reasons that C is unbeatable, and almost mandatory, for certain applications.


Portability and Efficiency

C is almost a portable assembly language. It is as close to the machine as possible while it is almost universally available for existing processor architectures. There is at least one C compiler for almost every existent architecture. And nowadays, because of highly optimized binaries generated by modern compilers, it’s not an easy task to improve on their output with hand written assembly.


Such is its portability and efficiency that “compilers, libraries, and interpreters of other programming languages are often implemented in C”. Interpreted languages like Python, Ruby, and PHP have their primary implementations written in C. It is even used by compilers for other languages to communicate with the machine. For example, C is the intermediate language underlying Eiffel and Forth. This means that, instead of generating machine code for every architecture to be supported, compilers for those languages just generate intermediate C code, and the C compiler handles the machine code generation.


C has also become a lingua franca for communicating between developers. As Alex Allain, Dropbox Engineering Manager and creator of Cprogramming.com, puts it:

“C is a great language for expressing common ideas in programming in a way that most people are comfortable with. Moreover, a lot of the principles used in C – for instance, argc and argv for command line parameters, as well as loop constructs and variable types – will show up in a lot of other languages you learn so you’ll be able to talk to people even if they don’t know C in a way that’s common to both of you.”

 Memory Manipulation

Arbitrary memory address access and pointer arithmetic is an important feature that makes C a perfect fit for system programming (operating systems and embedded systems).


At the hardware/software boundary, computer systems and microcontrollers map their peripherals and I/O pins into memory addresses. System applications must read and write to those custom memory locations to communicate with the world. So C’s ability to manipulate arbitrary memory addresses is imperative for system programming.


A microcontroller could be architected, for example, such that the byte in memory address 0x40008000 will be sent by the universal asynchronous receiver/transmitter (or UART, a common hardware component for communicating with peripherals) every time bit number 4 of address 0x40008001 is set to 1, and that after you set that bit, it will be automatically unset by the peripheral.


This would be the code for a C function that sends a byte through that UART:

#define UART_BYTE *(char *)0x40008000 
#define UART_SEND *(volatile char *)0x40008001 |= 0x08 

void send_uart(char byte) 
{ 
   UART_BYTE = byte;    // write byte to 0x40008000 address 
   UART_SEND;           // set bit number 4 of address 0x40008001 
}
The first line of the function will be expanded to:

*(char *)0x40008000 = byte;
This line tells the compiler to interpret the value 0x40008000 as a pointer to a char, then to dereference (give the value pointed to by) that pointer (with the leftmost * operator) and finally to assign byte value to that dereferenced pointer. In other words: write the value of variable byte to memory address 0x40008000.

The next line will be expanded to:

*(volatile char *)0x40008001 |= 0x08;
 In this line, we perform a bitwise OR operation on the value at address 0x40008001 and the value 0x08 (00001000 in binary, i.e., a 1 in bit number 4), and save the result back to address 0x40008001. In other words: we set bit 4 of the byte that is at address 0x40008001. We also declare that the value at address 0x40008001 is volatile. This tells the compiler that this value may be modified by processes external to our code, so the compiler won’t make any assumptions about the value in that address after writing to it. (In this case, this bit is unset by the UART hardware just after we set it by software.) This information is important for the compiler’s optimizer. If we did this inside a for loop, for example, without specifying that the value is volatile, the compiler might assume this value never changes after being set, and skip executing the command after the first loop.

Deterministic Usage of Resources

A common language feature that system programming cannot rely on is garbage collection, or even just dynamic allocation for some embedded systems. Embedded applications are very limited in time and memory resources. They are often used for real-time systems, where a non-deterministic call to the garbage collector cannot be afforded. And if dynamic allocation cannot be used because of the lack of memory, it is very important to have other mechanisms of memory management, like placing data in custom addresses, as C pointers allow. Languages that depend heavily on dynamic allocation and garbage collection wouldn’t be a fit for resource-limited systems.

Code Size

C has a very small runtime. And the memory footprint for its code is smaller than for most other languages.


When compared to C++, for example, a C-generated binary that goes to an embedded device is about half the size of a binary generated by similar C++ code. One of the main causes for that is exceptions support.


Exceptions are a great tool added by C++ over C, and, if not triggered and smartly implemented, they have practically no execution time overhead (but at the cost of increasing the code size).


Let’s see an example in C++:



// Class A declaration. Methods defined somewhere else; 
class A
{
public:
   A();                    // Constructor
   ~A();                   // Destructor (called when the object goes out of scope or is deleted)
   void myMethod();        // Just a method
};

// Class B declaration. Methods defined somewhere else;
class B
{
public:
   B();                    // Constructor
   ~B();                   // Destructor
   void myMethod();        // Just a method
};

// Class C declaration. Methods defined somewhere else;
class C
{
public:
   C();                    // Constructor
   ~C();                   // Destructor
   void myMethod();        // Just a method
};

void myFunction()
{
   A a;                    // Constructor a.A() called. (Checkpoint 1)
   {                       
      B b;                 // Constructor b.B() called. (Checkpoint 2)
      b.myMethod();        //                           (Checkpoint 3)
   }                       // b.~B() destructor called. (Checkpoint 4)
   {                       
      C c;                 // Constructor c.C() called. (Checkpoint 5)
      c.myMethod();        //                           (Checkpoint 6)
   }                       // c.~C() destructor called. (Checkpoint 7)
   a.myMethod();           //                           (Checkpoint 8)
}                          // a.~A() destructor called. (Checkpoint 9)
Methods of AB and C classes are defined somewhere else (for example in other files). Therefore the compiler cannot analyze them and cannot know if they will throw exceptions. So it must prepare to handle exceptions thrown from any of their constructors, destructors, or other method calls. Destructors should not throw (very bad practice), but the user could throw anyway, or they could throw indirectly by calling some function or method (explicitly or implicitly) that throws an exception.


If any of the calls in myFunction throw an exception, the stack unwinding mechanism must be able to call all the destructors for the objects that were already constructed. One implementation for the stack unwinding mechanism will use the return address of the last call from this function to verify the “checkpoint number” of the call that triggered the exception (this is the simple explanation). It does this by making use of an auxiliary autogenerated function (a kind of look-up table) that will be used for stack unwinding in case an exception is thrown from the body of that function, which will be similar to this:

// Possible autogenerated function
void autogeneratedStackUnwindingFor_myFunction(int checkpoint)
{
   switch (checkpoint)
   {
      // case 1 and 9: do nothing;
      case 3: b.~B(); goto destroyA;                     // jumps to location of destroyA label
      case 6: c.~C();                                    // also goes to destroyA as that is the next line
      destroyA:                                          // label
      case 2: case 4: case 5: case 7: case 8: a.~A();
   }
}
If the exception is thrown from checkpoints 1 and 9, no object needs destruction. For checkpoint 3, b and a must be destructed. For checkpoint 6, c and a must be destructed. In all cases the destruction order must be respected. For checkpoints 2, 4, 5, 7, and 8, only object a needs to be destructed.


This auxiliary function adds size to the code. This is part of the space overhead that C++ adds to C. Many embedded applications cannot afford this extra space. Therefore, C++ compilers for embedded systems often have a flag to disable exceptions. Disabling exceptions in C++ is not free, because the Standard Template Library heavily relies on exceptions to inform errors. Using this modified scheme, without exceptions, requires more training for C++ developers to detect possible issues or find bugs.


And, we are talking about C++, a language whose principle is: “You don’t pay for what you don’t use.” This increase on binary size gets worse for other languages that add additional overhead with other features that are very useful but cannot be afforded by embedded systems. While C does not give you the use of these extra features, it allows a much more compact code footprint than the other languages.


Reasons to Learn C

C is not a hard language to learn, so all the benefits from learning it will come quite cheap. Let’s see some of those benefits.

Lingua Franca

As already mentioned, C is a lingua franca for developers. Many implementations of new algorithms in books or on the internet are first (or only) made available in C by their authors. This gives the maximum possible portability for the implementation. I’ve seen programmers struggling on the internet to rewrite a C algorithm to other programming languages because he or she didn’t know very basic concepts of C.


Be aware that C is an old and widespread language, so you can find all kind of algorithms written in C around the web. Therefore you’ll very likely benefit from knowing this language.

Understand the Machine (Think in C)

When we discuss the behavior of certain portions of code, or certain features of other languages, with colleagues, we end up “talking in C:” Is this portion passing a “pointer” to the object or copying the entire object? Could any “cast” be happening here? And so on.


We would rarely discuss (or think) about the assembly instructions that a portion of code is executing when analyzing the behavior of a portion of code of a high level language. Instead, when discussing what the machine is doing, we speak (or think) pretty clearly in C.


Moreover, if you can’t stop and think that way about what you are doing, you may end up programming with some sort of superstition about how (magically) things are done.

Understand the Machine (Think in C)

Work on Many Interesting C Projects

Many interesting projects, from big database servers or operating system kernels, to small embedded applications you can even do at home for your personal satisfaction and fun, are done in C. There is no reason to stop doing things you may love for the single reason that you don’t know an old and small, but strong and time-proven programming language like C.


Work on Many Interesting C Projects

Conclusion

The Illuminati doesn't run the world. C programmers do.

The C programming language doesn’t seem to have an expiration date. It’s closeness to the hardware, great portability and deterministic usage of resources makes it ideal for low level development for such things as operating system kernels and embedded software. Its versatility, efficiency and good performance makes it an excellent choice for high complexity data manipulation software, like databases or 3D animation. The fact that many programming languages today are better than C for their intended use doesn’t mean that they beat C in all areas. C is still unsurpassed when performance is the priority.


The world is running on C-powered devices. We use these devices every day whether we realize it or not. C is the past, the present, and, as far as we can see, still the future for many areas of software.


About the author

Daniel Angel Muñoz Trejo

Source: toptal.com

    Blogger Comment

98 comments:

  1. this post are edifying in Classified Submission Site List India . An obligation of appreciation is all together for sharing this summary, Actually I found on different regions and after that proceeded this site so I found this is unfathomably improved and related.
    https://myseokhazana.com/


    ReplyDelete
  2. Extraordinary Article! I truly acknowledge this.You are so wonderful! This issue has and still is so significant and you have tended to it so Informative.
    Contact us :- https://myseokhazana.com

    ReplyDelete
  3. This is the most predictable blog which I have ever seen. I should need to express, this post will help me a ton to help my orchestrating on the SERP. Much restoring for sharing.
    https://myseokhazana.com


    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Vanskeligheter( van bi ) vil passere. På samme måte som( van điện từ ) regnet utenfor( van giảm áp ) vinduet, hvor nostalgisk( van xả khí ) er det som til slutt( van cửa ) vil fjerne( van công nghiệp ) himmelen.

    ReplyDelete
  7. Nice Presentation and its hopefull words..
    if you want a cheap web hostinng in web
    cheap web hosting company chennai

    ReplyDelete
  8. Anyone Wanna Join Whatsapp Groups
    Just Check This Link Out and Join many Quality Groups and Enjoy Your Life.
    Wanna Add You Group You can Do that Also Just Check this Out Whatsapp Group Links.


    Whatsapp Groups Links

    ReplyDelete
  9. Grow sale india classified ads website Buy&sell find just about anything

    post free classified ads in india

    ReplyDelete
  10. Whatsapp Group Link - 5000+ Updated Whatsapp Groups
    whatsapp group link Click The link And Join Whatsapp New Groups, Dating, Business promositions Groups https://grouplien.com

    ReplyDelete
  11. Your article is just amazing.You might be interested in:skyforce reloded

    ReplyDelete
  12. I Love your article. You can visit my website :
    showbox free apps

    ReplyDelete
  13. tweakbox for android download unlimited games and apps for you mobile.

    ReplyDelete
  14. Class College Education training Beauty teaching university academy lesson  teacher master student  spa manager  skin care learn eyelash extensions tattoo spray

    ReplyDelete
  15. BSc Cardio Vascular Technology is one of the best demanding courses in recent times. Here you can check the all details of this course and the best college to study in Bangalore for this course. Just click the below mentioned link.
    BSc Cardiac Care Technology Colleges In Bangalore

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. I love it! am going to share your post to my friends, keep posting! satta king

    ReplyDelete
  18. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Satta king

    ReplyDelete
  19. This exceptional internet site actually has all of guide the information I desired concerning this difficulty and didn’t recognize who to invite.

    ReplyDelete
  20. THANKS FOR SHARING THIS INFORMATION
    We provide Android Certification Course in Coimbatore by Qtree Technologies. Best Android app development Training institute in Coimbatore with 100% Job. To Know more about Android Training Courses in Coimbatore.
    android training institutes in coimbatore
    data science course in coimbatore
    data science training in coimbatore
    python training institute in coimbatore
    python course in coimbatore

    ReplyDelete
  21. Thank you so much for sharing this nice informations.
    android training institutes in coimbatore

    data science course in coimbatore

    data science training in coimbatore

    python course in coimbatore

    python training institute in coimbatore

    Software Testing Course in Coimbatore

    CCNA Course in Coimbatore

    ReplyDelete
  22. Here are the list of best Advertising Agency Riyadh, Branding Agency Riyadh & Marketing Agency In Riyadh. Click and you can check the details from the word which you love to know.

    ReplyDelete

  23. Java Training institute Coimbatore I am mani lives in Chennai. I have read your blog, its really useful for me. I did java development course in coimbatore at reputed
    java training centre this is useful for me to make a bright career in IT industry. So If anyone want to get best please vist Qtree Technologies.

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. I truly like you're composing style, incredible data, thank you for posting. Oregon Business Registry

    ReplyDelete
  26. I truly like you're composing style, incredible data, thank you for posting. Oregon Business Registry

    ReplyDelete
  27. I was taking a gander at some of your posts on this site and I consider this site is truly informational! Keep setting up..
    토토사이트

    ReplyDelete
  28. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work. 토토사이트

    ReplyDelete
  29. I'm happy to see the considerable subtle element here! Marketing tools

    ReplyDelete
  30. This article is very good please post in future articlepython course

    ReplyDelete
  31. Really infomational and educative article thanks publisher for sharing this wonderful info i have shared this article on my blog tecktak flippzilla
    and whatsaup, and Best smart tv

    ReplyDelete
  32. Attractive section of content. I simply stumbled upon your blog and in accession capital to assert that I acquire in fact enjoyed
    account your blog posts. Anyway I’ll be subscribing
    on your augment or even I success you access constantly quickl

    Also visit my site:online casino

    ReplyDelete
  33. Great post. I was checking continuously this blog and I am impressed!
    Extremely helpful info particularly the last part :) I care for such info
    a lot. I was seeking this particular information for
    a long time. Thank you and good luck.풀싸롱



    ReplyDelete
  34. Always i used to read smaller articles or reviews that also clear their motive, and that is also happening with this paragraph which I am reading here.
    안마

    Heya just wanted to giive you a quick heads up and let
    you know a few of thhe images aren’t loading properly.
    I’m not sre why but I think its a linkinng issue.
    I’ve tried it in two different web browsers and both show tthe same outcome.

    ReplyDelete
  35. Are you looking for Satta king results here? So here you can see the result of Jodi Satta King in time.Desawar Satta, Faridabad Satta, Gaziabad Satta, and Gali Satta play very prominent roles.And all these Satta King Results 16.10.2021 is published exclusively on this webpage.

    satta king

    satta king

    satta king result

    satta king Leak number

    ReplyDelete
  36. Really informative article post.Really looking forward to read more. Really Greatmymathlab answers

    ReplyDelete
  37. Your Site is very nice, and it's very helping us this post is unique and interesting, thank you for sharing this awesome information. and visit our blog site also sattaking



    Satta king
    Satta king chart
    Satta king gali
    Satta king Faridabad
    Satta king Desawar
    satta king Gaziabad
    Satta king online
    satta king fast

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. I am understand everything about this post i hope you are write awesome article like that.
    Satta King Online

    ReplyDelete
  40. drawingstudios.com Download the newest and hottest MOD APK games for Android. Continuous daily updates for mobile game lovers.

    ReplyDelete
  41. After all these years people are still spreading the myth and hype about C. They say C is a high-level language. C is not even a low-level language — it is a primitive coding language with pointers and macros dressed up with some structured syntax. But it does not really understand what structured programming is. C++ has done worse to OO — dressed itself up with some OO looking things like classes and inheritance, and then completely undermining the OO paradigm.
    This article smacks of old C programmers who want to hold onto their power. After 50 years the world should move on. Look how hardware has improved. And yet many people think this 50-year-old language that was flawed and compromised even for the time, must be perpetuated.
    C has achieved lock in, but not for technical excellence. The worse a technology, the more prone to lock in it is. C locks programmers into the wrong low-level structures like pointers. These are wrong, even for system programming, most of which does not depend on particular memory addresses.
    Let’s put C in its true place. It is an old, flawed, primitive language that was designed around compromises for small 1960s computers. C burdens programmers with many things that good languages should handle for programmers.
    “Oracle database development started in 1977, and its code was rewritten from assembly to C in 1983. It became one of the most popular databases in the world.”
    I’ll have a chuckle at that. Actually I have worked with the Oracle internals. It is no great programming. It actually illustrates what is wrong with C programming — platform differences left to the programmer to handle, rather than being handled in the compiler. Many cross-system programs must be knee deep in #define and #ifdef .
    That is burden on the programmer that a code generator should handle.
    https://www.quora.com/Why-does-C-accept-unsigned-long-unsigned-long-0-behavior-cannot-C-resolve-it-or-any-signification-when-accepting-it/answer/Ian-Joyner-1
    Sure programmers are taught how to handle that, even told this should be their responsibility. But that is wrong.
    “Despite the prevalence of higher-level languages, C continues to empower the world.”
This is just self-important aggrandisement about C. Sure the world is powered by computing, but that should not be attributed to any language. In fact, that is dangerous.
    And C is dangerous as an insecure language. C should not be used for anything above lowest levels of system programming. But even there we can do so much better.
    https://www.quora.com/Can-C-access-the-hardware-as-deep-as-Assembly/answer/Ian-Joyner-1
    C programmers love to swoop on new young programmers, tell them that they should learn C, they don’t need anything else. This is not teaching what programming really is. Sure the modern concepts of type systems, building algebras as classes, etc are all advanced for those starting programming, but they should not be exposed to the trite cult platitudes of advanced facilities being ‘training wheels for beginners’ or ‘crutches for weak programmers’. That appeals to programmer ego. Yes it works, generations of programmers have been misled. C teaches wrong thinking about programming.
    https://www.quora.com/Why-is-it-hard-to-understand-pointers-in-programming/answer/Ian-Joyner-1
    https://www.quora.com/What-are-the-memory-addresses-that-a-pointer-points-to-in-C-programs/answer/Ian-Joyner-1
    And we should put to bed this myth that everything originated in C from a vacuum. In fact, Ritchie only did some compiler work.
    https://www.quora.com/How-did-Dennis-Ritchie-and-Ken-Thompson-who-created-everything-without-knowing-OOP-manage-to-maintain-the-efficiency-of-their-programming-work/answer/Ian-Joyner-1
    https://medium.com/@ianjoyner/c-is-an-old-primitive-and-flawed-systems-coding-language-20d449290208
    So let’s get the truth about C and stop falling for hype articles like this one.

    Ian Joyner

    ReplyDelete